Skip to content

Commit aa40a90

Browse files
Add tests for #12731 (#9051)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 24c2d28 commit aa40a90

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎test/testbufferoverrun.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class TestBufferOverrun : public TestFixture {
165165
TEST_CASE(array_index_75);
166166
TEST_CASE(array_index_76);
167167
TEST_CASE(array_index_77);
168+
TEST_CASE(array_index_78);
168169
TEST_CASE(array_index_multidim);
169170
TEST_CASE(array_index_switch_in_for);
170171
TEST_CASE(array_index_for_in_for); // FP: #2634
@@ -2031,6 +2032,22 @@ class TestBufferOverrun : public TestFixture {
20312032
errout_str());
20322033
}
20332034

2035+
void array_index_78()
2036+
{
2037+
check("void f() {\n"
2038+
" struct {\n"
2039+
" int a; \n"
2040+
" void set(int i) { a = i; }\n"
2041+
" } v[4];\n"
2042+
" int idx = 0;\n"
2043+
" v[idx++].set(0);\n"
2044+
" v[idx++].set(0);\n"
2045+
" v[idx++].set(0);\n"
2046+
" v[idx++].set(0);\n"
2047+
"}\n");
2048+
ASSERT_EQUALS("", errout_str());
2049+
}
2050+
20342051
void array_index_multidim() {
20352052
check("void f()\n"
20362053
"{\n"

‎test/teststl.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,19 @@ class TestStl : public TestFixture {
10191019
" return outStr;\n"
10201020
"}\n");
10211021
ASSERT_EQUALS("", errout_str());
1022+
1023+
checkNormal("struct S {\n" // #12731
1024+
" void f(int j = 0) { a = j; }\n"
1025+
" int a;\n"
1026+
"};\n"
1027+
"std::vector<S*> g() {\n"
1028+
" int i = 0;\n"
1029+
" std::vector<S*> v;\n"
1030+
" v.push_back(new S());\n"
1031+
" v[i++].f(1);\n"
1032+
" return v;\n"
1033+
"}\n");
1034+
ASSERT_EQUALS("", errout_str());
10221035
}
10231036

10241037
void outOfBoundsSymbolic()

0 commit comments

Comments
 (0)