Null pointers: Fixed false negative for such code 'if (p && *p==0) {} *p = 0;'. Ticket: #2379
This commit is contained in:
parent
29d05cf5f2
commit
5f0206725b
|
@ -574,13 +574,13 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
|
||||
// vartok : token for the variable
|
||||
const Token *vartok = 0;
|
||||
if (Token::Match(tok, "if ( ! %var% ) {"))
|
||||
if (Token::Match(tok, "if ( ! %var% )|&&"))
|
||||
vartok = tok->tokAt(3);
|
||||
else if (Token::Match(tok, "if ( NULL|0 == %var% ) {"))
|
||||
else if (Token::Match(tok, "if ( NULL|0 == %var% )|&&"))
|
||||
vartok = tok->tokAt(4);
|
||||
else if (Token::Match(tok, "if ( %var% == NULL|0 ) {"))
|
||||
else if (Token::Match(tok, "if ( %var% == NULL|0 )|&&"))
|
||||
vartok = tok->tokAt(2);
|
||||
else if (Token::Match(tok, "if|while ( %var% ) {") &&
|
||||
else if (Token::Match(tok, "if|while ( %var% )|&&") &&
|
||||
!Token::simpleMatch(tok->tokAt(4)->link(), "} else"))
|
||||
vartok = tok->tokAt(2);
|
||||
else
|
||||
|
|
|
@ -823,6 +823,13 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("void foo(char *p) {\n"
|
||||
" if (p && *p == 0) {\n"
|
||||
" }\n"
|
||||
" printf(\"%c\", *p);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
|
||||
|
||||
check("void foo(abc *p) {\n"
|
||||
" if (!p) {\n"
|
||||
" }\n"
|
||||
|
|
Loading…
Reference in New Issue