Fixed #504 (false positive: null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2009-07-25 20:36:02 +02:00
parent 321106c39e
commit a6d696bf40
2 changed files with 13 additions and 1 deletions

View File

@ -1084,7 +1084,11 @@ void CheckOther::nullPointer()
if (varid == 0) if (varid == 0)
continue; continue;
for (const Token *tok1 = tok->previous(); tok1; tok1 = tok1->previous()) const Token *decltok = Token::findmatch(_tokenizer->tokens(), "%varid%", varid);
if (!Token::Match(decltok->tokAt(-3), "[;,(] %var% *"))
continue;
for (const Token *tok1 = tok->previous(); tok1 && tok1 != decltok; tok1 = tok1->previous())
{ {
if (tok1->varId() == varid) if (tok1->varId() == varid)
{ {

View File

@ -565,6 +565,14 @@ private:
" ;\n" " ;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
checkNullPointer("void foo(int x)\n"
"{\n"
" int a = 2 * x;"
" if (x == 0)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }