Null pointers: Fixed false positive for 'x && x->y'

This commit is contained in:
Daniel Marjamäki 2010-10-31 19:48:58 +01:00
parent 69c6358198
commit 285d76a413
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), "& (") && Token::Match(tok->next(), ". %var%"))
if (!Token::simpleMatch(tok->tokAt(-2), "& (") && tok->strAt(-1) != "&&" && Token::Match(tok->next(), ". %var%"))
return true;
if (Token::Match(tok->previous(), "[;{}=+-/(,] %var% ["))

View File

@ -362,6 +362,14 @@ private:
" p = p->next();\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(Document *doc) {\n"
" int x = doc && doc->x;\n"
" if (!doc) {\n"
" return;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void nullpointer5()