Null pointer: reduce false negatives in pointerDerefAndCheck

This commit is contained in:
Daniel Marjamäki 2011-08-02 17:04:07 +02:00
parent 825dce5c4e
commit 08f27564fa
2 changed files with 8 additions and 1 deletions

View File

@ -513,7 +513,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
// TODO: false negatives.
// - logical operators
// - while
if (tok->str() == "if" && Token::Match(tok->previous(), "; if ( !| %var% )"))
if (tok->str() == "if" && Token::Match(tok->previous(), "; if ( !| %var% )|%oror%|&&"))
{
const Token * vartok = tok->tokAt(2);
if (vartok->str() == "!")

View File

@ -406,6 +406,13 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 4\n", errout.str());
check("void foo(int *p)\n"
"{\n"
" *p = 0;\n"
" if (p || q) { }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 4\n", errout.str());
check("void foo(int *p)\n"
"{\n"
" bar(*p);\n"