Added regression test to #10602: FN nullptr

This commit is contained in:
orbitcowboy 2023-03-24 20:29:33 +01:00
parent fd8a7b9537
commit 38f9c81dd2
1 changed files with 22 additions and 0 deletions

View File

@ -142,6 +142,7 @@ private:
TEST_CASE(nullpointer96); // #11416
TEST_CASE(nullpointer97); // #11229
TEST_CASE(nullpointer98); // #11458
TEST_CASE(nullpointer99); // #10602
TEST_CASE(nullpointer_addressOf); // address of
TEST_CASE(nullpointerSwitch); // #2626
TEST_CASE(nullpointer_cast); // #4692
@ -2808,6 +2809,27 @@ private:
ASSERT_EQUALS("", errout.str());
}
void nullpointer99() // #10602
{
check("class A\n"
"{\n"
" int *foo(const bool b)\n"
" {\n"
" if(b)\n"
" return nullptr;\n"
" else\n"
" return new int [10];\n"
" }\n"
"public:\n"
" void bar(void)\n"
" {\n"
" int * buf = foo(true);\n"
" buf[2] = 0;" // <<
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:14]: (error) Null pointer dereference: buf\n", errout.str());
}
void nullpointer_addressOf() { // address of
check("void f() {\n"
" struct X *x = 0;\n"