diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 3c4d42621..12d0763a1 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -513,7 +513,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec() // TODO: false negatives. // - logical operators // - while - if (tok->str() == "if" && Token::Match(tok->previous(), "; if ( !| %var% )")) + if (tok->str() == "if" && Token::Match(tok->previous(), "; if ( !| %var% )|%oror%|&&")) { const Token * vartok = tok->tokAt(2); if (vartok->str() == "!") diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index df1ef762a..a747bddaa 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -406,6 +406,13 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 4\n", errout.str()); + check("void foo(int *p)\n" + "{\n" + " *p = 0;\n" + " if (p || q) { }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 4\n", errout.str()); + check("void foo(int *p)\n" "{\n" " bar(*p);\n"