Fixed #3914 (false positive null pointer dereference, assignment in conditional)

This commit is contained in:
Daniel Marjamäki 2012-07-23 10:05:55 +02:00
parent 188d2e143d
commit a733c9b603
2 changed files with 13 additions and 1 deletions

View File

@ -837,8 +837,13 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
const Token *tok2 = tok1->previous();
if (tok2 && (tok2->isArithmeticalOp() || tok2->str() == "(")) {
while (tok2 && !Token::Match(tok2, "[;{}?:]")) {
if (tok2->str() == ")")
if (tok2->str() == ")") {
tok2 = tok2->link();
if (Token::Match(tok2, "( %varid% =", varid)) {
tok2 = tok2->next();
break;
}
}
// guarded by &&
if (tok2->varId() == varid && tok2->next()->str() == "&&")
break;

View File

@ -743,6 +743,13 @@ private:
" $if(!p){}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // #3914 - false positive
" int *p;\n"
" ((p=ret()) && (x=*p));\n"
" if (p);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void nullpointer5() {