Skip to content

Commit 28a4846

Browse files
authored
Merge pull request diffblue#1568 from smowton/smowton/fix/java_div_by_zero
TG-977 Assert denominator non-zero when Java runtime exceptions are disabled
2 parents 7f53f02 + d0a844b commit 28a4846

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class DivideByZero {
2+
public static void main(String args[]) {
3+
int i=0;
4+
int j=10/i;
5+
}
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
DivideByZero.class
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
Denominator should be nonzero: FAILURE
7+
^VERIFICATION FAILED
8+
--
9+
^warning: ignoring

src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ codet java_bytecode_instrumentt::throw_exception(
143143
/// flag is set.
144144
/// \return Based on the value of the flag `throw_runtime_exceptions`,
145145
/// it returns code that either throws an ArithmeticException
146-
/// or is a skip
146+
/// or asserts a nonzero denominator.
147147
codet java_bytecode_instrumentt::check_arithmetic_exception(
148148
const exprt &denominator,
149149
const source_locationt &original_loc)
@@ -157,7 +157,11 @@ codet java_bytecode_instrumentt::check_arithmetic_exception(
157157
original_loc,
158158
"java.lang.ArithmeticException");
159159

160-
return code_skipt();
160+
code_assertt ret(binary_relation_exprt(denominator, ID_notequal, zero));
161+
ret.add_source_location()=original_loc;
162+
ret.add_source_location().set_comment("Denominator should be nonzero");
163+
ret.add_source_location().set_property_class("integer-divide-by-zero");
164+
return ret;
161165
}
162166

163167
/// Checks whether the array access array_struct[idx] is out-of-bounds,

0 commit comments

Comments
 (0)