X Tutup
Skip to content

Commit fe911f9

Browse files
committed
Simplify TestBufferOverrun test cases (known variable value)
1 parent 6f9886a commit fe911f9

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

test/testbufferoverrun.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,17 +1237,15 @@ class TestBufferOverrun : public TestFixture {
12371237
}
12381238

12391239
void array_index_38() { //ticket #3273
1240-
check("void aFunction()\n"
1241-
"{\n"
1242-
" const unsigned int arraySize = 10;\n"
1243-
" double aDoubleArray[ arraySize ];\n"
1244-
" unsigned int i = 0;\n"
1240+
check("void aFunction() {\n"
1241+
" double aDoubleArray[ 10 ];\n"
1242+
" unsigned int i; i = 0;\n"
12451243
" for( i = 0; i < 6; i++ )\n"
12461244
" {\n"
1247-
" unsigned int j = 0;\n"
1245+
" unsigned int j; j = 0;\n"
12481246
" for( j = 0; j < 5; j++ )\n"
12491247
" {\n"
1250-
" unsigned int x = 0;\n"
1248+
" unsigned int x; x = 0;\n"
12511249
" for( x = 0; x < 4; x++ )\n"
12521250
" {\n"
12531251
" }\n"
@@ -1303,15 +1301,15 @@ class TestBufferOverrun : public TestFixture {
13031301

13041302
check("void f()\n"
13051303
"{\n"
1306-
" char *p = (char*)malloc(10);\n"
1304+
" char *p; p = malloc(10);\n"
13071305
" p[10] = 7;\n"
13081306
" free(p);\n"
13091307
"}");
13101308
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'p[10]' accessed at index 10, which is out of bounds.\n", errout.str());
13111309

13121310
check("void f()\n"
13131311
"{\n"
1314-
" char *p = (char*)malloc(10);\n"
1312+
" char *p; p = malloc(10);\n"
13151313
" p[0] = 0;\n"
13161314
" p[9] = 9;\n"
13171315
" free(p);\n"
@@ -1320,7 +1318,7 @@ class TestBufferOverrun : public TestFixture {
13201318

13211319
check("void f()\n"
13221320
"{\n"
1323-
" char *p = new char[10];\n"
1321+
" char *p; p = new char[10];\n"
13241322
" p[0] = 0;\n"
13251323
" p[9] = 9;\n"
13261324
" delete [] p;\n"
@@ -1560,23 +1558,17 @@ class TestBufferOverrun : public TestFixture {
15601558
"}");
15611559
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' index a[6][12][2] out of bounds.\n", errout.str());
15621560

1563-
check("void f()\n"
1564-
"{\n"
1565-
" int i=2;\n"
1566-
" int ii=10;\n"
1567-
" char a[ii][ii][ii];\n"
1568-
" a[i*3][4*ii][ii] = 'a';\n"
1561+
check("void f() {\n"
1562+
" char a[10][10][10];\n"
1563+
" a[6][40][10] = 'a';\n"
15691564
"}");
1570-
ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[10][10][10]' index a[6][40][10] out of bounds.\n", errout.str());
1565+
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10][10][10]' index a[6][40][10] out of bounds.\n", errout.str());
15711566

1572-
check("void f()\n"
1573-
"{\n"
1574-
" int i=2;\n"
1575-
" int ii=1;\n"
1576-
" char a[ii][ii][ii];\n"
1577-
" a[i][i][i] = 'a';\n"
1567+
check("void f() {\n"
1568+
" char a[1][1][1];\n"
1569+
" a[2][2][2] = 'a';\n"
15781570
"}");
1579-
ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[1][1][1]' index a[2][2][2] out of bounds.\n", errout.str());
1571+
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[1][1][1]' index a[2][2][2] out of bounds.\n", errout.str());
15801572

15811573
check("void f()\n"
15821574
"{\n"

0 commit comments

Comments
 (0)
X Tutup