From 278808daa9aa066e3e35f349f0ce67fe657e1e5d Mon Sep 17 00:00:00 2001 From: Martin Ettl Date: Sat, 15 Aug 2015 00:49:07 +0200 Subject: [PATCH] #5238: Added a regression test case. --- test/testnullpointer.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index e0cc5989a..ae3d5039b 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -71,6 +71,7 @@ private: TEST_CASE(nullpointer26); // #3589 TEST_CASE(nullpointer27); // #6568 TEST_CASE(nullpointer28); // #6491 + TEST_CASE(nullpointer29); // #5238 TEST_CASE(nullpointer_addressOf); // address of TEST_CASE(nullpointerSwitch); // #2626 TEST_CASE(nullpointer_cast); // #4692 @@ -1305,6 +1306,23 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: s\n", errout.str()); } + void nullpointer29() { // #5238 + check("struct SomeStruct\n" + "{\n" + " bool item;\n" + "};\n" + "bool f1(bool bFlag)\n" + "{\n" + " SomeStruct *s = 0;\n" + " if (bFlag)\n" + " {\n" + " s = new SomeStruct;\n" + " }\n" + " return s != 0 || (s != 0 && !s->item);\n" + "}\n", true); + ASSERT_EQUALS("[test.cpp:12] -> [test.cpp:12]: (warning) Either the condition 's!=0' is redundant or there is possible null pointer dereference: s.\n", errout.str()); + } + void nullpointer_addressOf() { // address of check("void f() {\n" " struct X *x = 0;\n"