From 42a406ac5fccecada91b754ec1f3c93ae7179287 Mon Sep 17 00:00:00 2001 From: Martin Ettl Date: Thu, 30 Jul 2015 22:42:45 +0200 Subject: [PATCH] testbufferoverrun: Removed duplicate test case. --- test/testbufferoverrun.cpp | 120 +++++++++++++++---------------------- 1 file changed, 47 insertions(+), 73 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index c1760a5d3..90f0dd349 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -349,14 +349,6 @@ private: void array_index_2() { - check("void f()\n" - "{\n" - " char *str = new char[0x10];\n" - " str[15] = 0;\n" - " str[16] = 0;\n" - "}"); - ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[16]' accessed at index 16, which is out of bounds.\n", errout.str()); - check("void a(int i)\n" // valueflow "{\n" " char *str = new char[0x10];\n" @@ -368,71 +360,56 @@ private: void array_index_3() { - { - check("void f()\n" - "{\n" - " int val[50];\n" - " int i, sum=0;\n" - " for (i = 0; i < 100; i++)\n" - " sum += val[i];\n" - "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str()); - } + check("void f()\n" + "{\n" + " int val[50];\n" + " int i, sum=0;\n" + " for (i = 0; i < 100; i++)\n" + " sum += val[i];\n" + "}"); + ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str()); - { - check("void f()\n" - "{\n" - " int val[50];\n" - " int i, sum=0;\n" - " for (i = 1; i < 100; i++)\n" - " sum += val[i];\n" - "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str()); - } + check("void f()\n" + "{\n" + " int val[50];\n" + " int i, sum=0;\n" + " for (i = 1; i < 100; i++)\n" + " sum += val[i];\n" + "}"); + ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str()); + check("void f(int a)\n" + "{\n" + " int val[50];\n" + " int i, sum=0;\n" + " for (i = a; i < 100; i++)\n" + " sum += val[i];\n" + "}"); + ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str()); - { - check("void f(int a)\n" - "{\n" - " int val[50];\n" - " int i, sum=0;\n" - " for (i = a; i < 100; i++)\n" - " sum += val[i];\n" - "}"); - ASSERT_EQUALS("[test.cpp:6]: (error) Array 'val[50]' accessed at index 99, which is out of bounds.\n", errout.str()); - } + check("typedef struct g g2[3];\n" + "void foo(char *a)\n" + "{\n" + " for (int i = 0; i < 4; i++)\n" + " {\n" + " a[i]=0;\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); - { - check("typedef struct g g2[3];\n" - "void foo(char *a)\n" - "{\n" - " for (int i = 0; i < 4; i++)\n" - " {\n" - " a[i]=0;\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } + check("void foo(int argc)\n" + "{\n" + " char a[2];\n" + " for (int i = 4; i < argc; i++){}\n" + "}"); + ASSERT_EQUALS("", errout.str()); - { - check("void foo(int argc)\n" - "{\n" - " char a[2];\n" - " for (int i = 4; i < argc; i++)\n" - " {\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - { - check("void foo(int a[10]) {\n" - " for (int i=0;i<50;++i) {\n" - " a[i] = 0;\n" - " }\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index 49, which is out of bounds.\n", errout.str()); - } + check("void foo(int a[10]) {\n" + " for (int i=0;i<50;++i) {\n" + " a[i] = 0;\n" + " }\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index 49, which is out of bounds.\n", errout.str()); } void array_index_6() { @@ -656,7 +633,7 @@ private: "}"); ASSERT_EQUALS("", errout.str()); - // #2097.. + // #2097 check("void foo(int *p)\n" "{\n" " --p;\n" @@ -671,7 +648,6 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_11() { check("class ABC\n" "{\n" @@ -692,7 +668,6 @@ private: ASSERT_EQUALS("[test.cpp:13]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_12() { check("class Fred\n" "{\n" @@ -994,8 +969,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str()); } - void array_index_25() { - // ticket #1536 + void array_index_25() { // #1536 check("void foo()\n" "{\n" " long l[SOME_SIZE];\n"