Fixed #2251 (False positive: Possible null pointer reference)

This commit is contained in:
Daniel Marjamäki 2010-11-29 20:30:23 +01:00
parent cdb685c83c
commit 065af5c444
2 changed files with 9 additions and 1 deletions

View File

@ -115,7 +115,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
if (Token::Match(tok->tokAt(-3), "!!sizeof [;{}=+-/(,] * %var%"))
return true;
if (!Token::simpleMatch(tok->tokAt(-2), "& (") && tok->strAt(-1) != "&&" && Token::Match(tok->next(), ". %var%"))
if (!Token::simpleMatch(tok->tokAt(-2), "& (") && tok->strAt(-1) != "&" && tok->strAt(-1) != "&&" && Token::Match(tok->next(), ". %var%"))
return true;
if (Token::Match(tok->previous(), "[;{}=+-/(,] %var% ["))

View File

@ -609,6 +609,14 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// ticket #2251: taking the address of member
check("void f() {\n"
" Fred *fred = 0;\n"
" int x = &fred->x;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void nullpointer7()