Skip to content

Commit 7d78d58

Browse files
author
Daniel Kroening
committed
fix for non-byte array byte_extract flattening
1 parent 0779bbd commit 7d78d58

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

regression/cbmc/Pointer_array5/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

regression/cbmc/Pointer_array6/main.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
extern int nondet_int();
5+
6+
int main() {
7+
8+
int arraylen=nondet_int();
9+
10+
if(arraylen==3)
11+
{
12+
int** array_init = malloc(sizeof(int *)*arraylen);
13+
14+
// mis-align that pointer!
15+
char * char_ptr = (char *) array_init;
16+
char_ptr++;
17+
18+
int local_var;
19+
20+
int **array2=(int**)char_ptr;
21+
22+
// write
23+
array2[0]=&local_var;
24+
25+
// check
26+
int value=*array2[0];
27+
28+
assert(value==local_var);
29+
}
30+
31+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/solvers/flattening/flatten_byte_operators.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ exprt flatten_byte_extract(
117117
for(mp_integer i=0; i<num_elements; ++i)
118118
{
119119
// the most significant byte comes first in the concatenation!
120-
plus_exprt index(first_index, from_integer(i, offset_type));
120+
plus_exprt index(first_index, from_integer(num_elements-i-1, offset_type));
121121
concat.copy_to_operands(index_exprt(root, index));
122122
}
123123

0 commit comments

Comments
 (0)