Skip to content

Commit 9dce9bd

Browse files
committed
danmar#5811 false postive: (error) Null pointer dereference
1 parent e04351e commit 9dce9bd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/checknullpointer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ void CheckNullPointer::nullConstantDereference()
883883
else if (Token::simpleMatch(tok->previous(), ">> 0")) { // Only checking input stream operations is safe here, because otherwise 0 can be an integer as well
884884
const Token* tok2 = tok->previous(); // Find start of statement
885885
for (; tok2; tok2 = tok2->previous()) {
886-
if (Token::Match(tok2->previous(), ";|{|}|:"))
886+
if (Token::Match(tok2->previous(), ";|{|}|:|("))
887887
break;
888888
}
889889
if (Token::simpleMatch(tok2, "std :: cin"))
@@ -1064,4 +1064,3 @@ void CheckNullPointer::nullPointerDefaultArgError(const Token *tok, const std::s
10641064
{
10651065
reportError(tok, Severity::warning, "nullPointer", "Possible null pointer dereference if the default parameter value is used: " + varname);
10661066
}
1067-

test/testnullpointer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,15 @@ class TestNullPointer : public TestFixture {
21322132
" std::cout << i;\n" // Its no char* (#4240)
21332133
"}", true);
21342134
ASSERT_EQUALS("", errout.str());
2135+
2136+
// #5811 false postive: (error) Null pointer dereference
2137+
check("using namespace std;\n"
2138+
"std::string itoip(int ip) {\n"
2139+
" stringstream out;\n"
2140+
" out << ((ip >> 0) & 0xFF);\n"
2141+
" return out.str();\n"
2142+
"}n", true, "test.cpp", false);
2143+
ASSERT_EQUALS("", errout.str());
21352144
}
21362145

21372146
void functioncall() { // #3443 - function calls

0 commit comments

Comments
 (0)