Skip to content

Commit 741ab39

Browse files
committed
EXP39-C: Add malloc/realloc test
1 parent 94347c4 commit 741ab39

File tree

1 file changed

+18
-0
lines changed
  • c/cert/test/rules/EXP39-C

1 file changed

+18
-0
lines changed

c/cert/test/rules/EXP39-C/test.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,22 @@ int g(signed int x) { return x; }
7878
void test_compatible_functions() {
7979
signed (*f1)(int) = &g; // COMPLIANT
8080
int (*g1)(signed int) = &f; // COMPLIANT
81+
}
82+
83+
struct S2 {
84+
int a;
85+
int b;
86+
};
87+
88+
struct S3 {
89+
int a;
90+
int b;
91+
};
92+
93+
void test_realloc() {
94+
struct S2 *s2 = (struct S2 *)malloc(sizeof(struct S2));
95+
struct S3 *s3 = (struct S3 *)realloc(s2, sizeof(struct S3));
96+
s3->a; // NON_COMPLIANT
97+
memset(s3, 0, sizeof(struct S3));
98+
s3->a; // COMPLIANT
8199
}

0 commit comments

Comments
 (0)