diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 3a0d5a465..63f333c55 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -590,6 +590,14 @@ void CheckNullPointer::nullPointerByDeRefAndChec() { break; } + else if (Token::Match(tok1->previous(), "&&|%oror%")) + { + break; + } + else if (Token::Match(tok1->tokAt(-2), "&&|%oror% !")) + { + break; + } else if (CheckNullPointer::isPointerDeRef(tok1, unknown)) { nullPointerError(tok1, varname, tok->linenr()); diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 6b3301643..0c4afa9c1 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -584,6 +584,18 @@ private: " ;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #3023 - checked deref + check("void f(struct ABC *abc) {\n" + " WARN_ON(!abc || abc->x == 0);\n" + " if (!abc) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void f(struct ABC *abc) {\n" + " WARN_ON(!abc || abc->x == 7);\n" + " if (!abc) { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void nullpointer5()