Added test case from #8302 (#5138)

* Added test case from #8302 and a TODO

* Check with in C++ mode to get rid of TODO.

* Updated expected error message text

* Updated expected error message text
This commit is contained in:
orbitcowboy 2023-06-09 21:46:45 +02:00 committed by GitHub
parent a62fedc641
commit 6ea88c2758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -112,6 +112,7 @@ private:
TEST_CASE(deallocuse8); // #1765
TEST_CASE(deallocuse9); // #9781
TEST_CASE(deallocuse10);
TEST_CASE(deallocuse11); // #8302
TEST_CASE(doublefree1);
TEST_CASE(doublefree2);
@ -840,6 +841,22 @@ private:
ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str());
}
void deallocuse11() { // #8302
check("int f() {\n"
" int *array = new int[42];\n"
" delete [] array;\n"
" return array[1];" // <<
"}", true);
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout.str());
check("int f() {\n"
" int *array = (int*)malloc(40);\n"
" free(array);\n"
" return array[1];" // <<
"}");
ASSERT_EQUALS("[test.c:3] -> [test.c:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout.str());
}
void doublefree1() { // #3895
check("void f(char *p) {\n"
" if (x)\n"