Skip to content

Commit 0b5c882

Browse files
Update testbufferoverrun.cpp
1 parent 9e74aa5 commit 0b5c882

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎test/testbufferoverrun.cpp‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,34 @@ class TestBufferOverrun : public TestFixture {
36763676
"[test.cpp:8:12]: warning: Buffer is accessed out of bounds: a [bufferAccessOutOfBounds]\n"
36773677
"[test.cpp:7:11]: note: Assuming that condition 'i!=2' is not redundant\n"
36783678
"[test.cpp:8:12]: note: Buffer overrun\n", errout_str());
3679+
3680+
check("int a[3];\n"
3681+
"int f1(int i, bool b) {\n"
3682+
" int j = b ? i : -1;\n"
3683+
" return a[j];\n"
3684+
"}"
3685+
"int f2(int i, bool b) {\n"
3686+
" int j = b ? -1 : i;\n"
3687+
" return a[j];\n"
3688+
"}"
3689+
"int f3(int i, bool b) {\n"
3690+
" int j = -1;\n"
3691+
" if (b)\n"
3692+
" j = i;\n"
3693+
" return a[j];\n"
3694+
"}", s);
3695+
ASSERT_EQUALS("[test.cpp:4:13]: warning: Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\n"
3696+
"[test.cpp:3:13]: note: Assuming condition 'b' is false\n"
3697+
"[test.cpp:3:15]: note: Assignment 'j=b?i:-1', assigned value is -1\n"
3698+
"[test.cpp:4:13]: note: Negative array index\n"
3699+
"[test.cpp:7:13]: warning: Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\n"
3700+
"[test.cpp:6:13]: note: Assuming condition 'b' is true\n"
3701+
"[test.cpp:6:15]: note: Assignment 'j=b?-1:i', assigned value is -1\n"
3702+
"[test.cpp:7:13]: note: Negative array index\n"
3703+
"[test.cpp:12:13]: warning: Array 'a[3]' accessed at index -1, which is out of bounds. [negativeIndex]\n"
3704+
"[test.cpp:9:14]: note: Assignment 'j=-1', assigned value is -1\n"
3705+
"[test.cpp:10:9]: note: Assuming condition is false\n"
3706+
"[test.cpp:12:13]: note: Negative array index\n", errout_str());
36793707
}
36803708

36813709
void buffer_overrun_bailoutIfSwitch() {

0 commit comments

Comments
 (0)