From fe911f92e17eff52cd42aac48e42c8552dec20b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 13 Apr 2013 13:13:13 +0200 Subject: [PATCH] Simplify TestBufferOverrun test cases (known variable value) --- test/testbufferoverrun.cpp | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index f6e072199..3b95e8c30 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1237,17 +1237,15 @@ private: } void array_index_38() { //ticket #3273 - check("void aFunction()\n" - "{\n" - " const unsigned int arraySize = 10;\n" - " double aDoubleArray[ arraySize ];\n" - " unsigned int i = 0;\n" + check("void aFunction() {\n" + " double aDoubleArray[ 10 ];\n" + " unsigned int i; i = 0;\n" " for( i = 0; i < 6; i++ )\n" " {\n" - " unsigned int j = 0;\n" + " unsigned int j; j = 0;\n" " for( j = 0; j < 5; j++ )\n" " {\n" - " unsigned int x = 0;\n" + " unsigned int x; x = 0;\n" " for( x = 0; x < 4; x++ )\n" " {\n" " }\n" @@ -1303,7 +1301,7 @@ private: check("void f()\n" "{\n" - " char *p = (char*)malloc(10);\n" + " char *p; p = malloc(10);\n" " p[10] = 7;\n" " free(p);\n" "}"); @@ -1311,7 +1309,7 @@ private: check("void f()\n" "{\n" - " char *p = (char*)malloc(10);\n" + " char *p; p = malloc(10);\n" " p[0] = 0;\n" " p[9] = 9;\n" " free(p);\n" @@ -1320,7 +1318,7 @@ private: check("void f()\n" "{\n" - " char *p = new char[10];\n" + " char *p; p = new char[10];\n" " p[0] = 0;\n" " p[9] = 9;\n" " delete [] p;\n" @@ -1560,23 +1558,17 @@ private: "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10][10][10]' index a[6][12][2] out of bounds.\n", errout.str()); - check("void f()\n" - "{\n" - " int i=2;\n" - " int ii=10;\n" - " char a[ii][ii][ii];\n" - " a[i*3][4*ii][ii] = 'a';\n" + check("void f() {\n" + " char a[10][10][10];\n" + " a[6][40][10] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[10][10][10]' index a[6][40][10] out of bounds.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10][10][10]' index a[6][40][10] out of bounds.\n", errout.str()); - check("void f()\n" - "{\n" - " int i=2;\n" - " int ii=1;\n" - " char a[ii][ii][ii];\n" - " a[i][i][i] = 'a';\n" + check("void f() {\n" + " char a[1][1][1];\n" + " a[2][2][2] = 'a';\n" "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'a[1][1][1]' index a[2][2][2] out of bounds.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[1][1][1]' index a[2][2][2] out of bounds.\n", errout.str()); check("void f()\n" "{\n"