Skip to content

Commit 42cfa05

Browse files
romainbrenguierPetr Bauch
authored and
Petr Bauch
committed
Allocate nondet char array
make_nondet_infonite_char_array was not allocating the array as a dynamic object. This means if this code was added in a function called several time then the array would get overwritten each time. This problem was not visible by the string refinement as it associates a independent array to each string and does not care about memory allocation, but can be a problem for the interpreter.
1 parent 0547b72 commit 42cfa05

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,28 @@ exprt make_nondet_infinite_char_array(
632632
const array_typet array_type(
633633
java_char_type(), infinity_exprt(java_int_type()));
634634
const symbolt data_sym = get_fresh_aux_symbol(
635-
array_type,
635+
pointer_type(array_type),
636636
id2string(function_id),
637-
"nondet_infinite_array",
637+
"nondet_infinite_array_pointer",
638638
loc,
639639
ID_java,
640640
symbol_table);
641-
const symbol_exprt data_expr = data_sym.symbol_expr();
642-
code.add(code_declt(data_expr), loc);
643-
const side_effect_expr_nondett nondet_data(data_expr.type(), loc);
644-
code.add(code_assignt(data_expr, nondet_data), loc);
645-
return data_expr;
641+
642+
const exprt data_pointer = data_sym.symbol_expr();
643+
std::vector<const symbolt *> created_symbols;
644+
allocate_dynamic_object(
645+
data_pointer,
646+
array_type,
647+
symbol_table,
648+
loc,
649+
function_id,
650+
code,
651+
created_symbols,
652+
false);
653+
const exprt nondet_data = side_effect_expr_nondett(array_type, loc);
654+
const exprt data = dereference_exprt(data_pointer, array_type);
655+
code.add(code_assignt(data, nondet_data), loc);
656+
return data;
646657
}
647658

648659
/// Add a call to a primitive of the string solver, letting it know that

0 commit comments

Comments
 (0)