Merge pull request #883 from IOBYTE/master

Tests for git pull request #882.
This commit is contained in:
Matthias Krüger 2017-03-26 11:56:38 +02:00 committed by GitHub
commit 5d37070996
2 changed files with 31 additions and 0 deletions

View File

@ -291,6 +291,7 @@ private:
TEST_CASE(dealloc_use); TEST_CASE(dealloc_use);
TEST_CASE(dealloc_use_2); TEST_CASE(dealloc_use_2);
TEST_CASE(dealloc_use_3); TEST_CASE(dealloc_use_3);
TEST_CASE(dealloc_use_4); // #7960
// free a free'd pointer // free a free'd pointer
TEST_CASE(freefree1); TEST_CASE(freefree1);
@ -3199,6 +3200,21 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); 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() { void freefree1() {
check("void foo()\n" check("void foo()\n"
"{\n" "{\n"

View File

@ -144,6 +144,7 @@ private:
TEST_CASE(redundantVarAssignment); TEST_CASE(redundantVarAssignment);
TEST_CASE(redundantVarAssignment_7133); TEST_CASE(redundantVarAssignment_7133);
TEST_CASE(redundantVarAssignment_stackoverflow);
TEST_CASE(redundantMemWrite); TEST_CASE(redundantMemWrite);
TEST_CASE(varFuncNullUB); 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() { void redundantMemWrite() {
// Simple tests // Simple tests
check("void f() {\n" check("void f() {\n"