Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for #12592, #12786, #12908 #6616

Merged
merged 3 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class TestBufferOverrun : public TestFixture {
TEST_CASE(array_index_73); // #11530
TEST_CASE(array_index_74); // #11088
TEST_CASE(array_index_75);
TEST_CASE(array_index_76);
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 @@ -1991,6 +1992,26 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'buf[10]' accessed at index 10, which is out of bounds.\n", errout_str());
}

// #12592
void array_index_76()
{
check("void cb0(void*, int i) {\n"
" const char s[] = \"\";\n"
" (void)s[i];\n"
"}\n"
"void cb1(int i, void*) {\n"
" const char s[] = \"\";\n"
" (void)s[i];\n"
"}\n"
"void f() {\n"
" cb0(nullptr, 1);\n"
" cb1(1, nullptr);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Array 's[1]' accessed at index 1, which is out of bounds.\n"
"[test.cpp:7]: (error) Array 's[1]' accessed at index 1, which is out of bounds.\n",
errout_str());
}

void array_index_multidim() {
check("void f()\n"
"{\n"
Expand Down
6 changes: 6 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4609,6 +4609,12 @@ class TestCondition : public TestFixture {
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'q' is always true\n", errout_str());

check("void f() {\n" // #12786
" const int b[2] = {};\n"
" if (b) {}\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (style) Condition 'b' is always true\n", errout_str());

check("void f(int i) {\n"
" int j = 0;\n"
" switch (i) {\n"
Expand Down
13 changes: 13 additions & 0 deletions test/testconstructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class TestConstructors : public TestFixture {
TEST_CASE(uninitVar32); // ticket #8835
TEST_CASE(uninitVar33); // ticket #10295
TEST_CASE(uninitVar34); // ticket #10841
TEST_CASE(uninitVar35);
TEST_CASE(uninitVarEnum1);
TEST_CASE(uninitVarEnum2); // ticket #8146
TEST_CASE(uninitVarStream);
Expand Down Expand Up @@ -2957,6 +2958,18 @@ class TestConstructors : public TestFixture {
ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout_str());
}

void uninitVar35() {
check("struct S {\n" // #12908
" int a, b;\n"
" explicit S(int h = 0);\n"
" S(S&& s) : a(s.a), b(a.b) {\n"
" s.a = 0;\n"
" }\n"
"};\n"
"S::S(int h) : a(h), b(0) {}\n");
ASSERT_EQUALS("", errout_str());
}

void uninitVarArray1() {
check("class John\n"
"{\n"
Expand Down
Loading