Fixed #2689 (False positive: Possible null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2011-03-27 21:29:49 +02:00
parent dd5e15b40c
commit 57056bcf61
2 changed files with 17 additions and 0 deletions

View File

@ -660,6 +660,14 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
if (indentlevel == 0)
break;
--indentlevel;
if (null && indentlevel == 0)
{
// skip all "else" blocks because they are not executed in this execution path
while (Token::simpleMatch(tok2, "} else {"))
tok2 = tok2->tokAt(2)->link();
null = false;
}
}
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch"))

View File

@ -1001,6 +1001,15 @@ private:
" wilma->Reload();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void test(int *i) {\n"
" if(i == NULL) {\n"
" int b = 1;\n"
" } else {\n"
" int b = *i;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Test CheckNullPointer::nullConstantDereference