From ee083cd7a02c78b7f89790a750140383e3d50423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 9 Dec 2010 18:17:56 +0100 Subject: [PATCH] Fixed #2284 (False positive: Possible null pointer reference) --- lib/checknullpointer.cpp | 3 +++ test/testnullpointer.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 4f804beec..a5cbee827 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -742,6 +742,9 @@ private: dereference(checks, *it); } + else if (Token::simpleMatch(&tok, "( 0 &&")) + return tok.link(); + if (tok.varId() != 0) { bool unknown = false; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 89c67d70f..f3e684e57 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -513,6 +513,12 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("void f() {\n" + " Foo *p = 0;\n" + " bool b = (p && (p->type() == 1));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void foo()\n" "{\n" " int sz = sizeof((*(struct dummy *)0).x);\n"