From 08f27564fa3ffafb51ed7d99cefce68fe4f51366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 2 Aug 2011 17:04:07 +0200 Subject: [PATCH] Null pointer: reduce false negatives in pointerDerefAndCheck --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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"