Skip to content

Commit

Permalink
Add tests for #1644, #3929, #6109 (#5821)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 3, 2024
1 parent dd869cf commit 5e59652
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class TestBufferOverrun : public TestFixture {
TEST_CASE(array_index_72); // #11784
TEST_CASE(array_index_73); // #11530
TEST_CASE(array_index_74); // #11088
TEST_CASE(array_index_75);
TEST_CASE(array_index_multidim);
TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_for_in_for); // FP: #2634
Expand Down Expand Up @@ -1976,6 +1977,18 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

// #1644
void array_index_75()
{
check("void f() {\n"
" char buf[10];\n"
" int i = 10;\n"
" while (i >= 3)\n"
" buf[i--] = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout.str());
}

void array_index_multidim() {
check("void f()\n"
"{\n"
Expand Down
9 changes: 9 additions & 0 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,15 @@ class TestNullPointer : public TestFixture {
" return 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Null pointer dereference: myNull\n", errout.str());

check("struct T { bool g() const; };\n"
"void f(T* p) {\n"
" if (!p)\n"
" return;\n"
" while (p->g())\n"
" p = nullptr;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (warning) Possible null pointer dereference: p\n", errout.str());
}

void nullpointer94() // #11040
Expand Down
8 changes: 8 additions & 0 deletions test/teststring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,14 @@ class TestString : public TestFixture {
" ASSERT((void*)(\"def\") == 0);\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("class C {\n" // #6109
" void check(const char code[], bool validate = true, const char* filename = \"test.cpp\");\n"
" void f() {\n"
" check(\"class A<B&, C>;\", \"test.C\");\n"
" }\n"
"};\n");
ASSERT_EQUALS("[test.cpp:4]: (warning) Conversion of string literal \"test.C\" to bool always evaluates to true.\n", errout.str());
}

void deadStrcmp() {
Expand Down

0 comments on commit 5e59652

Please sign in to comment.