Skip to content

Commit 63953a0

Browse files
Add tests for shadow memory for strdup
Checks that the shadow memories of source and destination bufferes are independent.
1 parent 5003d79 commit 63953a0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
int main()
6+
{
7+
__CPROVER_field_decl_local("field1", (unsigned __CPROVER_bitvector[2])0);
8+
__CPROVER_field_decl_global("field1", (unsigned __CPROVER_bitvector[2])0);
9+
10+
char *s = (char *)malloc(3 * sizeof(char));
11+
assert(__CPROVER_get_field(&s[0], "field1") == 0);
12+
assert(__CPROVER_get_field(&s[1], "field1") == 0);
13+
14+
__CPROVER_set_field(&s[0], "field1", 1);
15+
__CPROVER_set_field(&s[1], "field1", 1);
16+
assert(__CPROVER_get_field(&s[0], "field1") == 1);
17+
assert(__CPROVER_get_field(&s[1], "field1") == 1);
18+
19+
// The shadow memories of the source and destination buffers
20+
// are independent.
21+
char *d = strdup(s);
22+
assert(__CPROVER_get_field(&s[0], "field1") == 1);
23+
assert(__CPROVER_get_field(&s[1], "field1") == 1);
24+
assert(__CPROVER_get_field(&d[0], "field1") == 0);
25+
assert(__CPROVER_get_field(&d[1], "field1") == 0);
26+
27+
__CPROVER_set_field(&d[0], "field1", 2);
28+
__CPROVER_set_field(&d[1], "field1", 2);
29+
assert(__CPROVER_get_field(&d[0], "field1") == 2);
30+
assert(__CPROVER_get_field(&d[1], "field1") == 2);
31+
assert(__CPROVER_get_field(&s[0], "field1") == 1);
32+
assert(__CPROVER_get_field(&s[1], "field1") == 1);
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FUTURE
2+
main.c
3+
--unwind 4
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

0 commit comments

Comments
 (0)