Skip to content

Commit 461e5cc

Browse files
committed
CheckBufferOverrun: Moved check from simplified to normal. This fixes a FP in asterisk.
1 parent 4ac5c78 commit 461e5cc

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

lib/checkbufferoverrun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
6868
checkBufferOverrun.checkStructVariable();
6969
checkBufferOverrun.checkBufferAllocatedWithStrlen();
7070
checkBufferOverrun.checkInsecureCmdLineArgs();
71-
checkBufferOverrun.bufferOverrun();
7271
checkBufferOverrun.arrayIndexThenCheck();
7372
checkBufferOverrun.negativeArraySize();
7473
}
7574

7675
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
7776
CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger);
77+
checkBufferOverrun.bufferOverrun();
7878
checkBufferOverrun.checkStringArgument();
7979
}
8080

test/testbufferoverrun.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -905,48 +905,48 @@ class TestBufferOverrun : public TestFixture {
905905
" a[-1] = 0;\n" // negative index
906906
" a[" + charMaxPlusOne.str() + "] = 0;\n" // 128/256 > CHAR_MAX
907907
"}\n").c_str());
908-
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n"
909-
"[test.cpp:4]: (error) Array 'a["+charMaxPlusOne.str()+"]' accessed at index "+charMaxPlusOne.str()+", which is out of bounds.\n", errout.str());
908+
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a["+charMaxPlusOne.str()+"]' accessed at index "+charMaxPlusOne.str()+", which is out of bounds.\n"
909+
"[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str());
910910

911911
check("void f(signed char n) {\n"
912912
" int a[n];\n" // n <= SCHAR_MAX
913913
" a[-1] = 0;\n" // negative index
914914
" a[128] = 0;\n" // 128 > SCHAR_MAX
915915
"}");
916-
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n"
917-
"[test.cpp:4]: (error) Array 'a[128]' accessed at index 128, which is out of bounds.\n", errout.str());
916+
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[128]' accessed at index 128, which is out of bounds.\n"
917+
"[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str());
918918

919919
check("void f(unsigned char n) {\n"
920920
" int a[n];\n" // n <= UCHAR_MAX
921921
" a[-1] = 0;\n" // negative index
922922
" a[256] = 0;\n" // 256 > UCHAR_MAX
923923
"}");
924-
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n"
925-
"[test.cpp:4]: (error) Array 'a[256]' accessed at index 256, which is out of bounds.\n", errout.str());
924+
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[256]' accessed at index 256, which is out of bounds.\n"
925+
"[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str());
926926

927927
check("void f(short n) {\n"
928928
" int a[n];\n" // n <= SHRT_MAX
929929
" a[-1] = 0;\n" // negative index
930930
" a[32768] = 0;\n" // 32768 > SHRT_MAX
931931
"}");
932-
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n"
933-
"[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout.str());
932+
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n"
933+
"[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str());
934934

935935
check("void f(unsigned short n) {\n"
936936
" int a[n];\n" // n <= USHRT_MAX
937937
" a[-1] = 0;\n" // negative index
938938
" a[65536] = 0;\n" // 65536 > USHRT_MAX
939939
"}");
940-
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n"
941-
"[test.cpp:4]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds.\n", errout.str());
940+
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[65536]' accessed at index 65536, which is out of bounds.\n"
941+
"[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str());
942942

943943
check("void f(signed short n) {\n"
944944
" int a[n];\n" // n <= SHRT_MAX
945945
" a[-1] = 0;\n" // negative index
946946
" a[32768] = 0;\n" // 32768 > SHRT_MAX
947947
"}");
948-
ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n"
949-
"[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n", errout.str());
948+
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[32768]' accessed at index 32768, which is out of bounds.\n"
949+
"[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str());
950950

951951
check("void f(int n) {\n"
952952
" int a[n];\n" // n <= INT_MAX
@@ -1123,9 +1123,9 @@ class TestBufferOverrun : public TestFixture {
11231123
" ptest->b[0][19] = 4;\n"
11241124
"}");
11251125
ASSERT_EQUALS("[test.cpp:9]: (error) Array 'test.a[10]' accessed at index 10, which is out of bounds.\n"
1126-
"[test.cpp:14]: (error) Array 'ptest.a[10]' accessed at index 10, which is out of bounds.\n"
11271126
"[test.cpp:10]: (error) Array 'test.b[10][5]' index test.b[10][2] out of bounds.\n"
11281127
"[test.cpp:11]: (error) Array 'test.b[10][5]' index test.b[0][19] out of bounds.\n"
1128+
"[test.cpp:14]: (error) Array 'ptest.a[10]' accessed at index 10, which is out of bounds.\n"
11291129
"[test.cpp:15]: (error) Array 'ptest.b[10][5]' index ptest.b[10][2] out of bounds.\n"
11301130
"[test.cpp:16]: (error) Array 'ptest.b[10][5]' index ptest.b[0][19] out of bounds.\n", errout.str());
11311131

@@ -1323,8 +1323,8 @@ class TestBufferOverrun : public TestFixture {
13231323
" y = var[ 0 ].arr[ 3 ];\n" // <-- array access out of bounds
13241324
" return y;\n"
13251325
"}");
1326-
ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n"
1327-
"[test.cpp:10]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds.\n", errout.str());
1326+
ASSERT_EQUALS("[test.cpp:10]: (error) Array 'var[0].arr[3]' accessed at index 3, which is out of bounds.\n"
1327+
"[test.cpp:10]: (error) Array 'var.arr[3]' accessed at index 3, which is out of bounds.\n", errout.str());
13281328

13291329
check("int f( )\n"
13301330
"{\n"
@@ -1368,8 +1368,8 @@ class TestBufferOverrun : public TestFixture {
13681368
"var[0].var[ 2 ] = 2;\n"
13691369
"var[0].var[ 4 ] = 4;\n" // <-- array access out of bounds
13701370
"}");
1371-
ASSERT_EQUALS("[test.cpp:9]: (error) Array 'var.var[3]' accessed at index 4, which is out of bounds.\n"
1372-
"[test.cpp:9]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds.\n", errout.str());
1371+
ASSERT_EQUALS("[test.cpp:9]: (error) Array 'var[0].var[3]' accessed at index 4, which is out of bounds.\n"
1372+
"[test.cpp:9]: (error) Array 'var.var[3]' accessed at index 4, which is out of bounds.\n", errout.str());
13731373

13741374
check("void f( ) {\n"
13751375
"struct S{\n"

0 commit comments

Comments
 (0)