Skip to content

Commit dcf2a81

Browse files
Add tests for shadow memory that maybe accessed via NULL
Checks that a shadow memory accesses are not confused by potential accesses through NULL pointers.
1 parent c50a8ad commit dcf2a81

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
__CPROVER_field_decl_local("field1", (_Bool)1);
7+
int x;
8+
int *y = NULL;
9+
int c;
10+
int *z;
11+
12+
// Goto-symex is expected to create a case split for dereferencing z.
13+
__CPROVER_assume(c > 0);
14+
if(c)
15+
z = &x;
16+
else
17+
z = y;
18+
19+
// Check initialization
20+
assert(__CPROVER_get_field(z, "field1") == 1);
21+
22+
// z actually points to x, which has valid shadow memory.
23+
__CPROVER_set_field(z, "field1", 0);
24+
assert(__CPROVER_get_field(z, "field1") == 0);
25+
assert(__CPROVER_get_field(&x, "field1") == 0);
26+
27+
// y is NULL, which has no valid shadow memory
28+
// and thus returns the default value.
29+
assert(__CPROVER_get_field(y, "field1") == 1);
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

0 commit comments

Comments
 (0)