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
Copy file name to clipboardExpand all lines: test/testbufferoverrun.cpp
+18Lines changed: 18 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4173,6 +4173,15 @@ class TestBufferOverrun : public TestFixture {
4173
4173
" a[i] = NULL;\n"
4174
4174
"}");
4175
4175
ASSERT_EQUALS("[test.cpp:4:6]: (error) Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str());
4176
+
4177
+
check("void f(const uint8_t* a) {\n"// 10421
4178
+
" uint8_t* p = (uint8_t*)malloc(20U * sizeof(uint8_t));\n"
4179
+
" if (!p) return false;\n"
4180
+
" for (uint8_t i = 1; i < 30; ++i)\n"
4181
+
" p[i] = a[i];\n"
4182
+
" free(p);\n"
4183
+
"}\n");
4184
+
ASSERT_EQUALS("[test.cpp:5:10]: (error) Array 'p[20]' accessed at index 29, which is out of bounds. [arrayIndexOutOfBounds]\n", errout_str());
4176
4185
}
4177
4186
4178
4187
// statically allocated buffer
@@ -5351,6 +5360,15 @@ class TestBufferOverrun : public TestFixture {
5351
5360
" f(a);\n"
5352
5361
"}\n");
5353
5362
ASSERT_EQUALS("[test.cpp:7:12] -> [test.cpp:9:6] -> [test.cpp:3:12]: (error) Array index out of bounds; 'p' buffer size is 4 and it is accessed at offset 20. [ctuArrayIndex]\n", errout_str());
5363
+
5364
+
ctu("void bar(int *p) { p[4] = 42; }\n"// #13403
5365
+
"void f() {\n"
5366
+
" int *p = (int*)malloc(4 * sizeof(int));\n"
5367
+
" if (!p) return;\n"
5368
+
" bar(p);\n"
5369
+
" free(p);\n"
5370
+
"}\n");
5371
+
ASSERT_EQUALS("[test.cpp:3:12] -> [test.cpp:4:9] -> [test.cpp:5:8] -> [test.cpp:1:20]: (error) Array index out of bounds; 'p' buffer size is 16 and it is accessed at offset 16. [ctuArrayIndex]\n", errout_str());
0 commit comments