You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reportError(tok, Severity::portability, "pointerOutOfBounds", "Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the " + object + ".\n"
178
+
reportError(tok, Severity::error, "pointerOutOfBounds", "Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the " + object + ".\n"
179
179
"Undefined behaviour: The result of this pointer arithmetic does not point into or just one element past the end of the " + object + ". Further information: https://www.securecoding.cert.org/confluence/display/seccode/ARR30-C.+Do+not+form+or+use+out+of+bounds+pointers+or+array+subscripts");
Copy file name to clipboardExpand all lines: test/testbufferoverrun.cpp
+17-2Lines changed: 17 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -232,6 +232,7 @@ class TestBufferOverrun : public TestFixture {
232
232
// char *p2 = a + 11 // UB
233
233
TEST_CASE(pointer_out_of_bounds_1);
234
234
TEST_CASE(pointer_out_of_bounds_2);
235
+
TEST_CASE(pointer_out_of_bounds_sub);
235
236
236
237
TEST_CASE(sprintf1);
237
238
TEST_CASE(sprintf2);
@@ -2947,7 +2948,13 @@ class TestBufferOverrun : public TestFixture {
2947
2948
" char a[10];\n"
2948
2949
" char *p = a + 100;\n"
2949
2950
"}");
2950
-
ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the array.\n", errout.str());
2951
+
ASSERT_EQUALS("[test.cpp:3]: (error) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the array.\n", errout.str());
2952
+
2953
+
check("void f() {\n"
2954
+
" char a[10];\n"
2955
+
" return a + 100;\n"
2956
+
"}");
2957
+
ASSERT_EQUALS("[test.cpp:3]: (error) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the array.\n", errout.str());
2951
2958
}
2952
2959
2953
2960
voidpointer_out_of_bounds_2() {
@@ -2956,7 +2963,7 @@ class TestBufferOverrun : public TestFixture {
2956
2963
" p += 100;\n"
2957
2964
" free(p);"
2958
2965
"}");
2959
-
ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the buffer.\n", errout.str());
2966
+
ASSERT_EQUALS("[test.cpp:3]: (error) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the buffer.\n", errout.str());
2960
2967
2961
2968
check("void f() {\n"
2962
2969
" char *p = malloc(10);\n"
@@ -2985,6 +2992,14 @@ class TestBufferOverrun : public TestFixture {
2985
2992
ASSERT_EQUALS("", errout.str());
2986
2993
}
2987
2994
2995
+
voidpointer_out_of_bounds_sub() {
2996
+
check("void f() {\n"
2997
+
" char x[10];\n"
2998
+
" return x-1;\n"
2999
+
"}");
3000
+
ASSERT_EQUALS("[test.cpp:3]: (error) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the array.\n", errout.str());
0 commit comments