C++: Add a test case resembling the example from ODASA-3940.

This commit is contained in:
Geoffrey White
2020-10-20 17:39:32 +01:00
parent 857a4d8a3f
commit 4630c69950
3 changed files with 15 additions and 0 deletions

View File

@@ -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. |

View File

@@ -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). |

View File

@@ -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)
}