throw ArithmeticException on divide-by-zero

This commit is contained in:
Joel Dice
2010-12-19 17:47:21 -07:00
parent d18240cbd6
commit 306f1282d0
12 changed files with 386 additions and 74 deletions

View File

@ -1665,6 +1665,11 @@ interpret(Thread* t)
case idiv: {
int32_t b = popInt(t);
int32_t a = popInt(t);
if (UNLIKELY(b == 0)) {
exception = makeThrowable(t, Machine::ArithmeticExceptionType);
goto throw_;
}
pushInt(t, a / b);
} goto loop;
@ -1968,6 +1973,11 @@ interpret(Thread* t)
int32_t b = popInt(t);
int32_t a = popInt(t);
if (UNLIKELY(b == 0)) {
exception = makeThrowable(t, Machine::ArithmeticExceptionType);
goto throw_;
}
pushInt(t, a % b);
} goto loop;
@ -2187,6 +2197,11 @@ interpret(Thread* t)
int64_t b = popLong(t);
int64_t a = popLong(t);
if (UNLIKELY(b == 0)) {
exception = makeThrowable(t, Machine::ArithmeticExceptionType);
goto throw_;
}
pushLong(t, a / b);
} goto loop;
@ -2269,6 +2284,11 @@ interpret(Thread* t)
int64_t b = popLong(t);
int64_t a = popLong(t);
if (UNLIKELY(b == 0)) {
exception = makeThrowable(t, Machine::ArithmeticExceptionType);
goto throw_;
}
pushLong(t, a % b);
} goto loop;