Skip to content

TG-977 Assert denominator non-zero when Java runtime exceptions are disabled #1568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
6 changes: 6 additions & 0 deletions regression/cbmc-java/divide_by_zero/DivideByZero.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class DivideByZero {
public static void main(String args[]) {
int i=0;
int j=10/i;
}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/divide_by_zero/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
DivideByZero.class

^EXIT=10$
^SIGNAL=0$
Denominator should be nonzero: FAILURE
^VERIFICATION FAILED
--
^warning: ignoring
8 changes: 6 additions & 2 deletions src/java_bytecode/java_bytecode_instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ codet java_bytecode_instrumentt::throw_exception(
/// flag is set.
/// \return Based on the value of the flag `throw_runtime_exceptions`,
/// it returns code that either throws an ArithmeticException
/// or is a skip
/// or asserts a nonzero denominator.
codet java_bytecode_instrumentt::check_arithmetic_exception(
const exprt &denominator,
const source_locationt &original_loc)
Expand All @@ -157,7 +157,11 @@ codet java_bytecode_instrumentt::check_arithmetic_exception(
original_loc,
"java.lang.ArithmeticException");

return code_skipt();
code_assertt ret(binary_relation_exprt(denominator, ID_notequal, zero));
ret.add_source_location()=original_loc;
ret.add_source_location().set_comment("Denominator should be nonzero");
ret.add_source_location().set_property_class("integer-divide-by-zero");
return ret;
}

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