Null pointers: Fixed false positive for 'x && x->y'
This commit is contained in:
parent
69c6358198
commit
285d76a413
|
@ -115,7 +115,7 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown)
|
||||||
if (Token::Match(tok->tokAt(-3), "!!sizeof [;{}=+-/(,] * %var%"))
|
if (Token::Match(tok->tokAt(-3), "!!sizeof [;{}=+-/(,] * %var%"))
|
||||||
return true;
|
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;
|
return true;
|
||||||
|
|
||||||
if (Token::Match(tok->previous(), "[;{}=+-/(,] %var% ["))
|
if (Token::Match(tok->previous(), "[;{}=+-/(,] %var% ["))
|
||||||
|
|
|
@ -362,6 +362,14 @@ private:
|
||||||
" p = p->next();\n"
|
" p = p->next();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void nullpointer5()
|
||||||
|
|
Loading…
Reference in New Issue