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