Skip to content

Commit 162103b

Browse files
committed
Adds memory-primitive check to contracts regression
CBMC relies on memory primitives to check frame conditions. We should ensure that regression tests for contracts do not use these primitives with invalid pointers. Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent 4ccf542 commit 162103b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#include <assert.h>
2+
#include <stdlib.h>
23

34
int y;
45
double z;
56

6-
void bar(char **c) __CPROVER_assigns(y, z, **c) __CPROVER_ensures(**c == 6)
7+
void bar(char *c) __CPROVER_assigns(y, z, *c) __CPROVER_ensures(*c == 6)
78
{
89
}
910

1011
int main()
1112
{
12-
char **b;
13+
char *b = malloc(sizeof(*b));
1314
bar(b);
14-
assert(**b == 6);
15+
assert(*b == 6);
1516

1617
return 0;
1718
}

regression/contracts/assigns_type_checking_valid_cases/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ void foo5(struct buf buffer) __CPROVER_assigns(buffer)
4545
buffer.len = 0;
4646
}
4747

48-
void foo6(struct buf *buffer)
49-
__CPROVER_assigns(buffer->data, *(buffer->data), buffer->len)
48+
void foo6(struct buf *buffer) __CPROVER_assigns(buffer->data, buffer->len)
5049
{
5150
buffer->data = malloc(sizeof(*(buffer->data)));
5251
*(buffer->data) = 1;

regression/contracts/chain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ elif echo $args_inst | grep -q -- "--dump-c" ; then
4444
rm "${name}-mod.c"
4545
fi
4646
$goto_instrument --show-goto-functions "${name}-mod.gb"
47-
$cbmc "${name}-mod.gb" ${args_cbmc}
47+
$cbmc "${name}-mod.gb" ${args_cbmc} --pointer-primitive-check

0 commit comments

Comments
 (0)