Skip to content

Commit 1e8d38d

Browse files
committed
Byte-operator lowering: use array comprehensions for non-constant width
Arrays with non-constant size are now encoded using array comprehensions. This lifts the prior limit of only being able to perform byte updates when at least the size of the update or the size of the target was known.
1 parent 8beda26 commit 1e8d38d

File tree

3 files changed

+444
-85
lines changed

3 files changed

+444
-85
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
4+
typedef struct
5+
{
6+
size_t len;
7+
char *name;
8+
} info_t;
9+
10+
void publish(info_t *info)
11+
{
12+
size_t size;
13+
__CPROVER_assume(size >= info->len);
14+
unsigned char *buffer = malloc(size);
15+
memcpy(buffer, info->name, info->len);
16+
if(info->len > 42)
17+
{
18+
__CPROVER_assert(buffer[42] == 42, "should pass");
19+
__CPROVER_assert(buffer[41] == 42, "should fail");
20+
}
21+
}
22+
23+
void main()
24+
{
25+
info_t info;
26+
size_t name_len;
27+
info.name = malloc(name_len);
28+
info.len = name_len;
29+
if(name_len > 42)
30+
info.name[42] = 42;
31+
publish(&info);
32+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^\[publish.assertion.1\] line 18 should pass: SUCCESS$
5+
^\[publish.assertion.2\] line 19 should fail: FAILURE$
6+
^\*\* 1 of \d+ failed
7+
^VERIFICATION FAILED$
8+
^EXIT=10$
9+
^SIGNAL=0$
10+
--
11+
^warning: ignoring

0 commit comments

Comments
 (0)