Skip to content

Commit

Permalink
Merge branch 'master' into jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvia González Rodríguez committed Feb 14, 2025
2 parents 6690513 + 973d34a commit 74eda32
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/assembler/expreval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,13 @@ VIntS evaluate(const std::shared_ptr<Expr> &expr,
}
FiExpr;
IfExpr(Div, v) {
return evaluate(v->lhs, variables) / evaluate(v->rhs, variables);
auto rhs_value = evaluate(v->rhs, variables);
if (rhs_value == 0) {
throw std::runtime_error(
"Division by zero error in expression evaluation.");
}

return evaluate(v->lhs, variables) / rhs_value;
}
FiExpr;
IfExpr(Mul, v) {
Expand All @@ -252,7 +258,13 @@ VIntS evaluate(const std::shared_ptr<Expr> &expr,
}
FiExpr;
IfExpr(Mod, v) {
return evaluate(v->lhs, variables) % evaluate(v->rhs, variables);
auto rhs_value = evaluate(v->rhs, variables);
if (rhs_value == 0) {
throw std::runtime_error(
"Modulo by zero error in expression evaluation.");
}

return evaluate(v->lhs, variables) % rhs_value;
}
FiExpr;
IfExpr(And, v) {
Expand Down

0 comments on commit 74eda32

Please sign in to comment.