@@ -72,25 +72,6 @@ class TestBufferOverrun : public TestFixture {
7272 checkBufferOverrun.writeOutsideBufferSize ();
7373 }
7474
75- void checkValueFlow (const char code[]) {
76- // Clear the error buffer..
77- errout.str (" " );
78-
79- Settings settings;
80- settings.valueFlow = true ;
81- settings.addEnabled (" warning" );
82-
83- // Tokenize..
84- Tokenizer tokenizer (&settings, this );
85- std::istringstream istr (code);
86- tokenizer.tokenize (istr, " test.cpp" );
87- tokenizer.simplifyTokenList2 ();
88-
89- // Check for buffer overruns..
90- CheckBufferOverrun checkBufferOverrun (&tokenizer, &settings, this );
91- checkBufferOverrun.bufferOverrun ();
92- }
93-
9475 void run () {
9576 TEST_CASE (noerr1);
9677 TEST_CASE (noerr2);
@@ -417,7 +398,8 @@ class TestBufferOverrun : public TestFixture {
417398 " for (i = 0; i < 100; i++)\n "
418399 " sum += val[i];\n "
419400 " }" );
420- ASSERT_EQUALS (" [test.cpp:6]: (error) Buffer is accessed out of bounds: val\n " , errout.str ());
401+ ASSERT_EQUALS (" [test.cpp:6]: (error) Buffer is accessed out of bounds: val\n "
402+ " [test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n " , errout.str ());
421403 }
422404
423405 {
@@ -428,7 +410,8 @@ class TestBufferOverrun : public TestFixture {
428410 " for (i = 1; i < 100; i++)\n "
429411 " sum += val[i];\n "
430412 " }" );
431- ASSERT_EQUALS (" [test.cpp:6]: (error) Buffer is accessed out of bounds: val\n " , errout.str ());
413+ ASSERT_EQUALS (" [test.cpp:6]: (error) Buffer is accessed out of bounds: val\n "
414+ " [test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n " , errout.str ());
432415 }
433416
434417
@@ -1825,7 +1808,8 @@ class TestBufferOverrun : public TestFixture {
18251808 " data[x] = 0;\n "
18261809 " }"
18271810 " }" );
1828- ASSERT_EQUALS (" [test.cpp:5]: (error) Buffer is accessed out of bounds: data\n " , errout.str ());
1811+ ASSERT_EQUALS (" [test.cpp:5]: (error) Buffer is accessed out of bounds: data\n "
1812+ " [test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n " , errout.str ());
18291813
18301814 check (" void f() {\n "
18311815 " char data[2];\n "
@@ -1834,7 +1818,8 @@ class TestBufferOverrun : public TestFixture {
18341818 " data[x] = 0;\n "
18351819 " }"
18361820 " }" );
1837- ASSERT_EQUALS (" [test.cpp:5]: (error) Buffer is accessed out of bounds: data\n " , errout.str ());
1821+ ASSERT_EQUALS (" [test.cpp:5]: (error) Buffer is accessed out of bounds: data\n "
1822+ " [test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n " , errout.str ());
18381823
18391824 check (" void f() {\n "
18401825 " char data[2];\n "
@@ -1843,7 +1828,8 @@ class TestBufferOverrun : public TestFixture {
18431828 " data[x] = 0;\n "
18441829 " }"
18451830 " }" );
1846- ASSERT_EQUALS (" [test.cpp:5]: (error) Buffer is accessed out of bounds: data\n " , errout.str ());
1831+ ASSERT_EQUALS (" [test.cpp:5]: (error) Buffer is accessed out of bounds: data\n "
1832+ " [test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n " , errout.str ());
18471833
18481834 check (" void f() {\n "
18491835 " char data[2];\n "
@@ -2071,11 +2057,11 @@ class TestBufferOverrun : public TestFixture {
20712057 }
20722058
20732059 void array_index_valueflow () {
2074- checkValueFlow (" void f(int i) {\n "
2075- " char str[3];\n "
2076- " str[i] = 0;\n "
2077- " if (i==10) {}\n "
2078- " }" );
2060+ check (" void f(int i) {\n "
2061+ " char str[3];\n "
2062+ " str[i] = 0;\n "
2063+ " if (i==10) {}\n "
2064+ " }" );
20792065 ASSERT_EQUALS (" [test.cpp:3]: (error) Array 'str[3]' accessed at index 10, which is out of bounds.\n " , errout.str ());
20802066 }
20812067
@@ -2614,7 +2600,8 @@ class TestBufferOverrun : public TestFixture {
26142600 " for (size_t i = 0; i <= 4; i++)\n "
26152601 " dst[i] = src[i];\n "
26162602 " } } }\n " );
2617- ASSERT_EQUALS (" [test.cpp:6]: (error) Buffer is accessed out of bounds: dst\n " , errout.str ());
2603+ ASSERT_EQUALS (" [test.cpp:6]: (error) Buffer is accessed out of bounds: dst\n "
2604+ " [test.cpp:6]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds.\n " , errout.str ());
26182605 }
26192606
26202607 void buffer_overrun_22 () { // ticket #3124
0 commit comments