-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add invalid address test case for invalid deallocation
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
tests/regression/75-invalid_dealloc/10-invalid-dealloc-union.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
extern void abort(void); | ||
#include <stdlib.h> | ||
|
||
extern int __VERIFIER_nondet_int(void); | ||
|
||
int main() | ||
{ | ||
union { | ||
void *p0; | ||
|
||
struct { | ||
char c[2]; | ||
int p1; | ||
int p2; | ||
} str; | ||
|
||
} data; | ||
|
||
// alloc 37B on heap | ||
data.p0 = malloc(37U); | ||
|
||
// avoid introducing a memleak | ||
void *ptr = data.p0; | ||
|
||
// this should be fine | ||
if(__VERIFIER_nondet_int()) { | ||
data.str.p2 = 20; | ||
} else { | ||
data.str.p2 = 30; | ||
} | ||
|
||
if(25 > data.str.p2) { | ||
// avoids memleak | ||
data.str.c[1] = sizeof data.str.p1; | ||
} | ||
|
||
// invalid free() | ||
free(data.p0);//WARN | ||
|
||
free(ptr);//NOWARN | ||
return 0; | ||
} |