@@ -160,11 +160,12 @@ codet java_bytecode_instrumentt::check_arithmetic_exception(
160
160
original_loc,
161
161
" java.lang.ArithmeticException" );
162
162
163
- code_assertt ret (binary_relation_exprt (denominator, ID_notequal, zero));
164
- ret.add_source_location ()=original_loc;
165
- ret.add_source_location ().set_comment (" Denominator should be nonzero" );
166
- ret.add_source_location ().set_property_class (" integer-divide-by-zero" );
167
- return ret;
163
+ source_locationt assertion_loc = original_loc;
164
+ assertion_loc.set_comment (" Denominator should be nonzero" );
165
+ assertion_loc.set_property_class (" integer-divide-by-zero" );
166
+
167
+ return create_fatal_assertion (
168
+ binary_relation_exprt (denominator, ID_notequal, zero), assertion_loc);
168
169
}
169
170
170
171
// / Checks whether the array access array_struct[idx] is out-of-bounds,
@@ -195,19 +196,17 @@ codet java_bytecode_instrumentt::check_array_access(
195
196
" java.lang.ArrayIndexOutOfBoundsException" );
196
197
197
198
code_blockt bounds_checks;
198
- bounds_checks.add (code_assertt (ge_zero));
199
- bounds_checks.operands ().back ().add_source_location ()=original_loc;
200
- bounds_checks.operands ().back ().add_source_location ()
201
- .set_comment (" Array index should be >= 0" );
202
- bounds_checks.operands ().back ().add_source_location ()
203
- .set_property_class (" array-index-out-of-bounds-low" );
204
-
205
- bounds_checks.add (code_assertt (lt_length));
206
- bounds_checks.operands ().back ().add_source_location ()=original_loc;
207
- bounds_checks.operands ().back ().add_source_location ()
208
- .set_comment (" Array index should be < length" );
209
- bounds_checks.operands ().back ().add_source_location ()
210
- .set_property_class (" array-index-out-of-bounds-high" );
199
+
200
+ source_locationt low_check_loc = original_loc;
201
+ low_check_loc.set_comment (" Array index should be >= 0" );
202
+ low_check_loc.set_property_class (" array-index-out-of-bounds-low" );
203
+
204
+ source_locationt high_check_loc = original_loc;
205
+ high_check_loc.set_comment (" Array index should be < length" );
206
+ high_check_loc.set_property_class (" array-index-out-of-bounds-high" );
207
+
208
+ bounds_checks.add (create_fatal_assertion (ge_zero, low_check_loc));
209
+ bounds_checks.add (create_fatal_assertion (lt_length, high_check_loc));
211
210
212
211
return bounds_checks;
213
212
}
@@ -246,11 +245,12 @@ codet java_bytecode_instrumentt::check_class_cast(
246
245
}
247
246
else
248
247
{
249
- code_assertt assert_class (class_cast_check);
250
- assert_class.add_source_location ().
251
- set_comment (" Dynamic cast check" );
252
- assert_class.add_source_location ().
253
- set_property_class (" bad-dynamic-cast" );
248
+ source_locationt check_loc = original_loc;
249
+ check_loc.set_comment (" Dynamic cast check" );
250
+ check_loc.set_property_class (" bad-dynamic-cast" );
251
+
252
+ codet assert_class = create_fatal_assertion (class_cast_check, check_loc);
253
+
254
254
check_code=std::move (assert_class);
255
255
}
256
256
@@ -283,12 +283,11 @@ codet java_bytecode_instrumentt::check_null_dereference(
283
283
equal_expr,
284
284
original_loc, " java.lang.NullPointerException" );
285
285
286
- code_assertt check ((not_exprt (equal_expr)));
287
- check.add_source_location ()
288
- .set_comment (" Throw null" );
289
- check.add_source_location ()
290
- .set_property_class (" null-pointer-exception" );
291
- return check;
286
+ source_locationt check_loc = original_loc;
287
+ check_loc.set_comment (" Null pointer check" );
288
+ check_loc.set_property_class (" null-pointer-exception" );
289
+
290
+ return create_fatal_assertion (not_exprt (equal_expr), check_loc);
292
291
}
293
292
294
293
// / Checks whether `length`>=0 and throws NegativeArraySizeException/
@@ -313,11 +312,11 @@ codet java_bytecode_instrumentt::check_array_length(
313
312
original_loc,
314
313
" java.lang.NegativeArraySizeException" );
315
314
316
- code_assertt check (ge_zero) ;
317
- check. add_source_location () .set_comment (" Array size should be >= 0" );
318
- check. add_source_location ()
319
- . set_property_class ( " array-create-negative-size " );
320
- return check ;
315
+ source_locationt check_loc ;
316
+ check_loc .set_comment (" Array size should be >= 0" );
317
+ check_loc. set_property_class ( " array-create-negative-size " );
318
+
319
+ return create_fatal_assertion (ge_zero, check_loc) ;
321
320
}
322
321
323
322
// / Checks whether `expr` requires instrumentation, and if so adds it
0 commit comments