From d75ef01d2b7cd19eae0dff8dbf43b8b3dedf2f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 Oct 2011 15:48:54 +0200 Subject: [PATCH] Null pointer: Added inconclusive error message when calling member function of NULL object. --- lib/checknullpointer.cpp | 3 +++ test/testnullpointer.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 656cbb5a7..8cc92bb28 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -850,6 +850,9 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() else if (CheckNullPointer::isPointerDeRef(tok2, unknown)) nullPointerError(tok2, pointerName, linenr, inconclusive); + else if (unknown && _settings->inconclusive) + nullPointerError(tok2, pointerName, linenr, true); + else break; } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 8b2d9b555..abd2b8573 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -1370,6 +1370,19 @@ private: " }\n" "}"); ASSERT_EQUALS("", errout.str()); + + { + const char code[] = "void f(Fred *fred) {\n" + " if (fred == NULL) { }\n" + " fred->x();\n" + "}"; + + check(code); // non-inconclusive + ASSERT_EQUALS("", errout.str()); + + check(code, true); // inconclusive + ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: fred - otherwise it is redundant to check if fred is null at line 2\n", errout.str()); + } } // Test CheckNullPointer::nullConstantDereference