Fixed #3023 (False positive: no possible null pointer dereference here: 'WARN_ON(!abc || abc->x == 0);')

This commit is contained in:
Daniel Marjamäki 2011-08-20 09:47:55 +02:00
parent dd09b24208
commit 27b29e5b8e
2 changed files with 20 additions and 0 deletions

View File

@ -590,6 +590,14 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
{
break;
}
else if (Token::Match(tok1->previous(), "&&|%oror%"))
{
break;
}
else if (Token::Match(tok1->tokAt(-2), "&&|%oror% !"))
{
break;
}
else if (CheckNullPointer::isPointerDeRef(tok1, unknown))
{
nullPointerError(tok1, varname, tok->linenr());

View File

@ -584,6 +584,18 @@ private:
" ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #3023 - checked deref
check("void f(struct ABC *abc) {\n"
" WARN_ON(!abc || abc->x == 0);\n"
" if (!abc) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(struct ABC *abc) {\n"
" WARN_ON(!abc || abc->x == 7);\n"
" if (!abc) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void nullpointer5()