Fixed #2647 (False positive: Possible null pointer dereference (member function call))

This commit is contained in:
Daniel Marjamäki 2011-03-12 20:57:19 +01:00
parent 6bd56dbe20
commit f3728c0b76
2 changed files with 17 additions and 0 deletions

View File

@ -418,6 +418,16 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
if (var && (var->isLocal() || var->isArgument())) if (var && (var->isLocal() || var->isArgument()))
isLocal = true; isLocal = true;
// member function may or may not nullify the pointer if it's global (#2647)
if (!isLocal)
{
const Token *tok2 = tok1;
while (Token::Match(tok2, "%var% ."))
tok2 = tok2->tokAt(2);
if (Token::Match(tok2,"%var% ("))
continue;
}
// count { and } using tok2 // count { and } using tok2
unsigned int indentlevel2 = 0; unsigned int indentlevel2 = 0;
for (const Token *tok2 = tok1->tokAt(3); tok2; tok2 = tok2->next()) for (const Token *tok2 = tok1->tokAt(3); tok2; tok2 = tok2->next())

View File

@ -336,6 +336,13 @@ private:
"}"); "}");
ASSERT_EQUALS("",errout.str()); ASSERT_EQUALS("",errout.str());
check("Fred *fred;\n"
"void f() {\n"
" fred->foo();\n"
" if (fred) { }\n"
"}");
ASSERT_EQUALS("",errout.str());
// #2641 - local pointer, function call // #2641 - local pointer, function call
check("void f() {\n" check("void f() {\n"
" ABC *abc;\n" " ABC *abc;\n"