File tree 5 files changed +31
-7
lines changed
jbmc/regression/jbmc/array-cell-sensitivity-negative-size
5 files changed +31
-7
lines changed Original file line number Diff line number Diff line change
1
+ public class Test {
2
+ public static void check (Integer t ) {
3
+ if (t != null )
4
+ try {
5
+ Integer [] arr = new Integer [-7 ];
6
+ assert false ;
7
+ } catch (NegativeArraySizeException e ) {
8
+ assert false ;
9
+ }
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ Test.class
3
+ --function Test.check
4
+ line 5 Array size should be >= 0: FAILURE
5
+ ^EXIT=10$
6
+ ^SIGNAL=0$
7
+ --
8
+ --
9
+ Test that defining an array with negative size does not crash JBMC
Original file line number Diff line number Diff line change @@ -180,14 +180,15 @@ exprt field_sensitivityt::get_fields(
180
180
#ifdef ENABLE_ARRAY_FIELD_SENSITIVITY
181
181
else if (
182
182
ssa_expr.type ().id () == ID_array &&
183
- to_array_type (ssa_expr.type ()).size ().id () == ID_constant &&
184
- numeric_cast_v<mp_integer>(
185
- to_constant_expr (to_array_type (ssa_expr.type ()).size ())) <=
186
- max_field_sensitivity_array_size)
183
+ to_array_type (ssa_expr.type ()).size ().id () == ID_constant)
187
184
{
185
+ const mp_integer mp_array_size = numeric_cast_v<mp_integer>(
186
+ to_constant_expr (to_array_type (ssa_expr.type ()).size ()));
187
+ if (mp_array_size < 0 || mp_array_size > max_field_sensitivity_array_size)
188
+ return ssa_expr;
189
+
188
190
const array_typet &type = to_array_type (ssa_expr.type ());
189
- const std::size_t array_size =
190
- numeric_cast_v<std::size_t >(to_constant_expr (type.size ()));
191
+ const std::size_t array_size = numeric_cast_v<std::size_t >(mp_array_size);
191
192
192
193
array_exprt result (type);
193
194
result.reserve_operands (array_size);
Original file line number Diff line number Diff line change @@ -141,7 +141,10 @@ const boolbv_widtht::entryt &boolbv_widtht::get_entry(const typet &type) const
141
141
if (total>(1 <<30 )) // realistic limit
142
142
throw analysis_exceptiont (" array too large for flattening" );
143
143
144
- entry.total_width = numeric_cast_v<std::size_t >(total);
144
+ if (total < 0 )
145
+ entry.total_width = 0 ;
146
+ else
147
+ entry.total_width = numeric_cast_v<std::size_t >(total);
145
148
}
146
149
}
147
150
else if (type_id==ID_vector)
You can’t perform that action at this time.
0 commit comments