From 38f9c81dd23d2076121bd84c5564edca0d7f7bdb Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Fri, 24 Mar 2023 20:29:33 +0100 Subject: [PATCH] Added regression test to #10602: FN nullptr --- test/testnullpointer.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index cc8194e40..3edddf773 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -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"