Skip to content

Commit

Permalink
testbufferoverrun.cpp: properly reset settings and adjusted some test…
Browse files Browse the repository at this point in the history
… results
  • Loading branch information
firewave committed Mar 5, 2024
1 parent e31a615 commit f8f94be
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3451,9 +3451,7 @@ class TestBufferOverrun : public TestFixture {
"test.cpp:2:note:Assign p, buffer with size 10\n"
"test.cpp:3:note:Buffer overrun\n", errout.str());

// TODO: need to reset this but it breaks other tests
(void)settingsOld;
//settings0 = settingsOld;
settings0 = settingsOld;
}

void buffer_overrun_bailoutIfSwitch() {
Expand Down Expand Up @@ -3805,7 +3803,7 @@ class TestBufferOverrun : public TestFixture {
" std::string hi = \"hi\" + val;\n"
" std::cout << hi << std::endl;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic '\"hi\"+val' is out of bounds.\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour, pointer arithmetic '\"hi\"+val' is out of bounds.\n", errout.str());

check("void f(const char* s, int len) {\n" // #11026
" const char* end = s + len;\n"
Expand Down Expand Up @@ -4053,14 +4051,14 @@ class TestBufferOverrun : public TestFixture {
" for (int i = 0; i < 3; i++)\n"
" a[i] = NULL;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());

check("void f() {\n"
" int **a = new int*[2];\n"
" for (int i = 0; i < 3; i++)\n"
" a[i] = NULL;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 2, which is out of bounds.\n", errout.str());
}

// statically allocated buffer
Expand Down Expand Up @@ -5136,7 +5134,7 @@ class TestBufferOverrun : public TestFixture {
" int* p = new int[d];\n"
" return p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3] -> [test.cpp:5]: (warning, inconclusive) Memory allocation size is negative.\n", errout.str());
ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Memory allocation size is negative.\n", errout.str());
}

void negativeArraySize() {
Expand Down

0 comments on commit f8f94be

Please sign in to comment.