Skip to content

Commit

Permalink
Add invalid address test case for invalid deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstanb committed Oct 4, 2023
1 parent 395c30d commit 055d9cc
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/regression/75-invalid_dealloc/10-invalid-dealloc-union.c
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;
}

0 comments on commit 055d9cc

Please sign in to comment.