diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 8429c823e..433523d46 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -1268,7 +1268,6 @@ private: return tok2; } } - return tok2; } return &tok; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 190a068dc..1acc2ec69 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -54,6 +54,7 @@ private: TEST_CASE(nullpointer18); // #1927 TEST_CASE(nullpointer19); // #3811 TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z) + TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;) TEST_CASE(nullpointer_castToVoid); // #3771 TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it TEST_CASE(nullConstantDereference); // Dereference NULL constant @@ -1280,6 +1281,16 @@ private: TODO_ASSERT_EQUALS("error", "", errout.str()); } + void nullpointer21() { // #4038 - fp: if (x) p=q; else return; + check("void f(int x) {\n" + " int *p = 0;\n" + " if (x) p = q;\n" + " else return;\n" + " *p = 0;\n" // <- p is not NULL + "}"); + ASSERT_EQUALS("", errout.str()); + } + void nullpointer_castToVoid() { // #3771 check("void f () {\n" " int *buf = NULL;\n"