File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed
cpp/ql/test/query-tests/Critical/SizeCheck Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 22| test.c:17:20:17:25 | call to malloc | Type 'double' is 8 bytes, but only 5 bytes are allocated. |
33| test.c:32:19:32:24 | call to malloc | Type 'float' is 4 bytes, but only 2 bytes are allocated. |
44| test.c:33:20:33:25 | call to malloc | Type 'double' is 8 bytes, but only 4 bytes are allocated. |
5+ | test.c:59:15:59:20 | call to malloc | Type 'MyUnion' is 128 bytes, but only 8 bytes are allocated. |
Original file line number Diff line number Diff line change 66| test.c:17:20:17:25 | call to malloc | Allocated memory (5 bytes) is not a multiple of the size of 'double' (8 bytes). |
77| test.c:32:19:32:24 | call to malloc | Allocated memory (2 bytes) is not a multiple of the size of 'float' (4 bytes). |
88| test.c:33:20:33:25 | call to malloc | Allocated memory (4 bytes) is not a multiple of the size of 'double' (8 bytes). |
9+ | test.c:59:15:59:20 | call to malloc | Allocated memory (8 bytes) is not a multiple of the size of 'MyUnion' (128 bytes). |
Original file line number Diff line number Diff line change @@ -43,5 +43,18 @@ void good1(void) {
4343 free (dptr );
4444}
4545
46-
47-
46+ typedef struct _myStruct
47+ {
48+ int x , y ;
49+ } MyStruct ;
50+
51+ typedef union _myUnion
52+ {
53+ MyStruct ms ;
54+ char data [128 ];
55+ } MyUnion ;
56+
57+ void test_union () {
58+ MyUnion * a = malloc (sizeof (MyUnion )); // GOOD
59+ MyUnion * b = malloc (sizeof (MyStruct )); // BAD (too small)
60+ }
You can’t perform that action at this time.
0 commit comments