diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 68b370545..5d2631c8b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -291,6 +291,7 @@ private: TEST_CASE(dealloc_use); TEST_CASE(dealloc_use_2); TEST_CASE(dealloc_use_3); + TEST_CASE(dealloc_use_4); // #7960 // free a free'd pointer TEST_CASE(freefree1); @@ -3199,6 +3200,21 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); } + void dealloc_use_4() { // #7960 + check("class SR {\n" + "public:\n" + " void dostuff();\n" + " int* m_data;\n" + "};\n" + "void SR::dostuff() {\n" + " SR sr;\n" + " delete m_data;\n" + " sr.m_data = new SVec;\n" + " *m_data = 123;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void freefree1() { check("void foo()\n" "{\n" diff --git a/test/testother.cpp b/test/testother.cpp index 0c654da6d..d6bbd1d07 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -144,6 +144,7 @@ private: TEST_CASE(redundantVarAssignment); TEST_CASE(redundantVarAssignment_7133); + TEST_CASE(redundantVarAssignment_stackoverflow); TEST_CASE(redundantMemWrite); TEST_CASE(varFuncNullUB); @@ -5172,6 +5173,20 @@ private: } + void redundantVarAssignment_stackoverflow() { + check("typedef struct message_node {\n" + " char code;\n" + " size_t size;\n" + " struct message_node *next, *prev;\n" + "} *message_list;\n" + "static message_list remove_message_from_list(message_list m) {\n" + " m->prev->next = m->next;\n" + " m->next->prev = m->prev;\n" + " return m->next;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void redundantMemWrite() { // Simple tests check("void f() {\n"