diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 33c0e4032..9ae24bd24 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -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; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 601b9fae3..fb34173ad 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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() {