Tests for git pull request #882.

This commit is contained in:
Robert Reif 2017-03-25 15:46:25 -04:00
parent 1feada4c21
commit 3dba1b1739
2 changed files with 31 additions and 0 deletions

View File

@ -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"

View File

@ -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"