Skip to content

Commit e1d31bf

Browse files
committed
CPP: Add a test of ArrayArgSizeMismatch.ql.
1 parent aba73f4 commit e1d31bf

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.cpp:24:4:24:7 | arr3 | Array of size 3 passed to $@ which expects an array of size 4. | test.cpp:8:6:8:6 | g | g |
2+
| test.cpp:40:9:40:12 | data | Array of size 0 passed to $@ which expects an array of size 4. | test.cpp:9:6:9:6 | h | h |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Conversion/ArrayArgSizeMismatch.ql
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
typedef unsigned long size_t;
3+
void *malloc(size_t size);
4+
5+
#define NUM (4)
6+
7+
void f(int *vs);
8+
void g(int vs[4]);
9+
void h(float fs[NUM]);
10+
11+
struct myStruct
12+
{
13+
unsigned int num;
14+
float data[0];
15+
};
16+
17+
void test(float f3[3], float f4[4], float f5[5], float *fp)
18+
{
19+
int arr3[3], arr4[4], arr5[5];
20+
21+
f(arr3); // GOOD
22+
f(arr4); // GOOD
23+
f(arr5); // GOOD
24+
g(arr3); // BAD
25+
g(arr4); // GOOD
26+
g(arr5); // GOOD
27+
28+
h(f3); // BAD [NOT DETECTED]
29+
h(f4); // GOOD
30+
h(f5); // GOOD
31+
h(fp); // GOOD
32+
33+
{
34+
// variable size struct
35+
myStruct *ms;
36+
37+
ms = (myStruct *)malloc(sizeof(myStruct) + (4 * sizeof(float)));
38+
ms->num = 4;
39+
ms->data[0] = ms->data[1] = ms->data[2] = ms->data[3] = 0;
40+
h(ms->data); // GOOD [FALSE POSITIVE]
41+
}
42+
43+
{
44+
// char array
45+
char ca[4 * sizeof(int)];
46+
47+
g((int *)ca); // GOOD
48+
}
49+
};

0 commit comments

Comments
 (0)