#5238: Added a regression test case.

This commit is contained in:
Martin Ettl 2015-08-15 00:49:07 +02:00
parent 640ec3a099
commit 278808daa9
1 changed files with 18 additions and 0 deletions

View File

@ -71,6 +71,7 @@ private:
TEST_CASE(nullpointer26); // #3589 TEST_CASE(nullpointer26); // #3589
TEST_CASE(nullpointer27); // #6568 TEST_CASE(nullpointer27); // #6568
TEST_CASE(nullpointer28); // #6491 TEST_CASE(nullpointer28); // #6491
TEST_CASE(nullpointer29); // #5238
TEST_CASE(nullpointer_addressOf); // address of TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626 TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692 TEST_CASE(nullpointer_cast); // #4692
@ -1305,6 +1306,23 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: s\n", errout.str()); 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 void nullpointer_addressOf() { // address of
check("void f() {\n" check("void f() {\n"
" struct X *x = 0;\n" " struct X *x = 0;\n"