Skip to content

Commit a6557f8

Browse files
committed
Null pointer: Fixed false positive discovered by Travis when self-checking cppcheck
1 parent 189360a commit a6557f8

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

lib/checknullpointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
735735
nullPointerError(tok2, pointerName, vartok, inconclusive);
736736
else if (unknown)
737737
nullPointerError(tok2, pointerName, vartok, true);
738-
if (Token::Match(tok2, "%var% ?"))
738+
if (Token::Match(tok2, "%var% %oror%|&&|?"))
739739
break;
740740
}
741741
}

test/testnullpointer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,12 @@ class TestNullPointer : public TestFixture {
17261726
" return q ? p->x : 0;\n"
17271727
"}");
17281728
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:2]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n", errout.str());
1729+
1730+
check("int f(ABC *p) {\n" // FP : return &&
1731+
" if (!p) {}\n"
1732+
" return p && p->x;\n"
1733+
"}");
1734+
ASSERT_EQUALS("", errout.str());
17291735
}
17301736

17311737
// Test CheckNullPointer::nullConstantDereference
@@ -2215,8 +2221,8 @@ class TestNullPointer : public TestFixture {
22152221
}
22162222

22172223
void functioncalllibrary() {
2218-
Settings settings;
2219-
Tokenizer tokenizer(&settings,this);
2224+
Settings settings1;
2225+
Tokenizer tokenizer(&settings1,this);
22202226
std::istringstream code("void f() { int a,b; x(a,b); }");
22212227
tokenizer.tokenize(code,"test.c");
22222228
const Token *xtok = Token::findsimplematch(tokenizer.tokens(), "x");

0 commit comments

Comments
 (0)