Fixed #2808 (False positive 'Possible null pointer dereference')

This commit is contained in:
Daniel Marjamäki 2011-06-21 18:45:30 +02:00
parent be27b35fc4
commit e4f6d4c987
2 changed files with 14 additions and 2 deletions

View File

@ -516,9 +516,13 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
for (const Token *tok1 = tok->previous(); tok1 && tok1 != decltok; tok1 = tok1->previous())
{
if (tok1->str() == ")" && Token::Match(tok1->link()->tokAt(-3), "%varid% = %var%", varid))
if (tok1->str() == ")" && Token::Match(tok1->link()->previous(), "%var% ("))
{
break;
const Token *tok2 = tok1->link();
while (tok2 && !Token::Match(tok2, "[;{}]"))
tok2 = tok2->previous();
if (Token::Match(tok2, "[;{}] %varid% = %var%", varid))
break;
}
if (tok1->str() == ")" && Token::Match(tok1->link()->previous(), "while ( %varid%", varid))

View File

@ -487,6 +487,14 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(x *p)\n"
"{\n"
" p = aa->bar(p->next);\n"
" if (!p)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo(struct ABC *abc)\n"
"{\n"
" abc = abc ? abc->next : 0;\n"