From 6edf35ebf56305766fb50582c85d980bf819fdcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 15 Jan 2011 12:09:36 +0100 Subject: [PATCH] Fixed #2463 (false positive: possible nullpointer dereference) --- lib/checknullpointer.cpp | 3 +++ test/testnullpointer.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 0a327f372..e5f03cdf2 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -466,6 +466,9 @@ void CheckNullPointer::nullPointerByDeRefAndChec() break; } + if (tok1->str() == "break") + break; + if (tok1->varId() == varid && !Token::Match(tok1->previous(), "[?:]")) { // unknown : this is set by isPointerDeRef if it is diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 63550e950..cd485e920 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -417,6 +417,26 @@ private: " return FALSE;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // Ticket #2463 + check("struct A \n" + "{\n" + " B* W;\n" + "\n" + " void f() {\n" + " switch (InData) {\n" + " case 2:\n" + " if (!W) return;\n" + " W->foo();\n" + " break;\n" + " case 3:\n" + " f();\n" + " if (!W) return;\n" + " break;\n" + " }\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void nullpointer5()