Fixed #2681 (False negative: Possible null pointer dereference)
This commit is contained in:
parent
c1138cf7f9
commit
2c6e4c423a
|
@ -201,7 +201,7 @@ void CheckNullPointer::nullPointerAfterLoop()
|
|||
// TODO: Aren't there false negatives. Shouldn't other loops be handled such as:
|
||||
// - while ( ! %var% )
|
||||
// - while ( %var% && .. )
|
||||
if (! Token::Match(tok, "while ( %var% )"))
|
||||
if (! Token::Match(tok, "while ( %var% )|&&"))
|
||||
continue;
|
||||
|
||||
// Get variable id for the loop variable
|
||||
|
@ -217,7 +217,7 @@ void CheckNullPointer::nullPointerAfterLoop()
|
|||
const std::string varname(tok->strAt(2));
|
||||
|
||||
// Locate the end of the while loop body..
|
||||
const Token *tok2 = tok->tokAt(4)->link();
|
||||
const Token *tok2 = tok->next()->link()->next()->link();
|
||||
|
||||
// Check if the variable is dereferenced after the while loop
|
||||
while (0 != (tok2 = tok2 ? tok2->next() : 0))
|
||||
|
|
|
@ -88,12 +88,12 @@ private:
|
|||
check("void foo(const Token *tok)\n"
|
||||
"{\n"
|
||||
" while (tok && tok->str() == \"=\")\n"
|
||||
" tok = tok->tokAt(-2);\n"
|
||||
" tok = tok->next();\n"
|
||||
"\n"
|
||||
" if (tok->str() != \";\")\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check if tok is null at line 3\n", "", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check if tok is null at line 3\n", errout.str());
|
||||
|
||||
check("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue