mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix division by zero crashes in instructions
Previously, rgbasm could crash with a floating point exception if an instruction includes a division or modulo by 0. Fixes #49.
This commit is contained in:
@@ -316,6 +316,9 @@ rpn_DIV(struct Expression * expr, struct Expression * src1,
|
||||
struct Expression * src2)
|
||||
{
|
||||
joinexpr();
|
||||
if (src2->nVal == 0) {
|
||||
fatalerror("division by zero");
|
||||
}
|
||||
expr->nVal = (expr->nVal / src2->nVal);
|
||||
pushbyte(expr, RPN_DIV);
|
||||
}
|
||||
@@ -325,6 +328,9 @@ rpn_MOD(struct Expression * expr, struct Expression * src1,
|
||||
struct Expression * src2)
|
||||
{
|
||||
joinexpr();
|
||||
if (src2->nVal == 0) {
|
||||
fatalerror("division by zero");
|
||||
}
|
||||
expr->nVal = (expr->nVal % src2->nVal);
|
||||
pushbyte(expr, RPN_MOD);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user