From 27b29e5b8e5f1d1790cd7a91b97d0c1f8fe1bf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 20 Aug 2011 09:47:55 +0200 Subject: [PATCH] Fixed #3023 (False positive: no possible null pointer dereference here: 'WARN_ON(!abc || abc->x == 0);') --- lib/checknullpointer.cpp | 8 ++++++++ test/testnullpointer.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) 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()