mirror of
https://github.com/github/codeql.git
synced 2025-12-20 10:46:30 +01:00
C++: Add a test case resembling the example from ODASA-3940.
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
| test.c:17:20:17:25 | call to malloc | Type 'double' is 8 bytes, but only 5 bytes are allocated. |
|
||||
| test.c:32:19:32:24 | call to malloc | Type 'float' is 4 bytes, but only 2 bytes are allocated. |
|
||||
| test.c:33:20:33:25 | call to malloc | Type 'double' is 8 bytes, but only 4 bytes are allocated. |
|
||||
| test.c:59:15:59:20 | call to malloc | Type 'MyUnion' is 128 bytes, but only 8 bytes are allocated. |
|
||||
|
||||
@@ -6,3 +6,4 @@
|
||||
| test.c:17:20:17:25 | call to malloc | Allocated memory (5 bytes) is not a multiple of the size of 'double' (8 bytes). |
|
||||
| test.c:32:19:32:24 | call to malloc | Allocated memory (2 bytes) is not a multiple of the size of 'float' (4 bytes). |
|
||||
| test.c:33:20:33:25 | call to malloc | Allocated memory (4 bytes) is not a multiple of the size of 'double' (8 bytes). |
|
||||
| test.c:59:15:59:20 | call to malloc | Allocated memory (8 bytes) is not a multiple of the size of 'MyUnion' (128 bytes). |
|
||||
|
||||
@@ -43,5 +43,18 @@ void good1(void) {
|
||||
free(dptr);
|
||||
}
|
||||
|
||||
typedef struct _myStruct
|
||||
{
|
||||
int x, y;
|
||||
} MyStruct;
|
||||
|
||||
typedef union _myUnion
|
||||
{
|
||||
MyStruct ms;
|
||||
char data[128];
|
||||
} MyUnion;
|
||||
|
||||
void test_union() {
|
||||
MyUnion *a = malloc(sizeof(MyUnion)); // GOOD
|
||||
MyUnion *b = malloc(sizeof(MyStruct)); // BAD (too small)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user