Ticket #6098, added regression test

This commit is contained in:
orbitcowboy 2021-12-07 08:50:29 +01:00
parent 33c55f77a8
commit bca27bf7d2
1 changed files with 23 additions and 0 deletions

View File

@ -129,6 +129,7 @@ private:
TEST_CASE(nullpointer87); // #9291 TEST_CASE(nullpointer87); // #9291
TEST_CASE(nullpointer88); // #9949 TEST_CASE(nullpointer88); // #9949
TEST_CASE(nullpointer89); // #10640 TEST_CASE(nullpointer89); // #10640
TEST_CASE(nullpointer90); // #6098
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
@ -2636,6 +2637,28 @@ private:
errout.str()); errout.str());
} }
void nullpointer90() // #6098
{
check("std::string definitionToName(Definition *ctx)\n"
"{\n"
" if (ctx->definitionType()==Definition::TypeMember)\n" // possible null pointer dereference
" {\n"
" return \"y\";\n"
" }\n"
" else if (ctx)\n" // ctx is checked against null
" {\n"
" if(ctx->definitionType()!=Definition::TypeMember)\n"
" {\n"
" return \"x\";\n"
" }\n"
" }\n"
" return \"unknown\";\n"
"}");
ASSERT_EQUALS(
"[test.cpp:7] -> [test.cpp:3]: (warning) Either the condition 'ctx' is redundant or there is possible null pointer dereference: ctx.\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"