Fixed #504 (false positive: null pointer dereference)
This commit is contained in:
parent
321106c39e
commit
a6d696bf40
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue