From 68beffca043ba23114824ed46408e65cb0d653ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 8 Jan 2011 17:16:52 +0100 Subject: [PATCH] Fixed #2437 (false positive: possible null pointer dereference: tok2) --- lib/checknullpointer.cpp | 2 +- test/testnullpointer.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 4bd058f45..c29c72897 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -461,7 +461,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec() break; } - if (tok1->varId() == varid) + if (tok1->varId() == varid && !Token::Match(tok1->previous(), "[?:]")) { // unknown : this is set by isPointerDeRef if it is // uncertain diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 7f5020339..e610ab618 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -397,6 +397,14 @@ private: " ;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void foo(struct ABC *abc)\n" + "{\n" + " abc = abc ? abc->next : 0;\n" + " if (!abc)\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void nullpointer5()