fix bug: check division by zero
authorQuoc-Sang Phan <dark2bright@gmail.com>
Tue, 23 Jan 2018 20:47:37 +0000 (12:47 -0800)
committerQuoc-Sang Phan <dark2bright@gmail.com>
Tue, 23 Jan 2018 20:47:37 +0000 (12:47 -0800)
src/main/gov/nasa/jpf/jvm/bytecode/DDIV.java

index 4c20b68dbda931fbeaccea80ae372712790d5b2e..c14099be1e54b550c0025fcfbd141ca2dc014957 100644 (file)
@@ -35,6 +35,11 @@ public class DDIV extends Instruction implements JVMInstruction {
     double v1 = frame.popDouble();
     double v2 = frame.popDouble();
     
+    if (v1 == 0) {
+        return ti.createAndThrowException("java.lang.ArithmeticException",
+                                          "division by zero");
+    }
+
     double r = v2 / v1;
     
     frame.pushDouble(r);