File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -240,7 +240,13 @@ VIntS evaluate(const std::shared_ptr<Expr> &expr,
240240 }
241241 FiExpr;
242242 IfExpr (Div, v) {
243- return evaluate (v->lhs , variables) / evaluate (v->rhs , variables);
243+ auto rhs_value = evaluate (v->rhs , variables);
244+ if (rhs_value == 0 ) {
245+ throw std::runtime_error (
246+ " Division by zero error in expression evaluation." );
247+ }
248+
249+ return evaluate (v->lhs , variables) / rhs_value;
244250 }
245251 FiExpr;
246252 IfExpr (Mul, v) {
@@ -252,7 +258,13 @@ VIntS evaluate(const std::shared_ptr<Expr> &expr,
252258 }
253259 FiExpr;
254260 IfExpr (Mod, v) {
255- return evaluate (v->lhs , variables) % evaluate (v->rhs , variables);
261+ auto rhs_value = evaluate (v->rhs , variables);
262+ if (rhs_value == 0 ) {
263+ throw std::runtime_error (
264+ " Modulo by zero error in expression evaluation." );
265+ }
266+
267+ return evaluate (v->lhs , variables) % rhs_value;
256268 }
257269 FiExpr;
258270 IfExpr (And, v) {
You can’t perform that action at this time.
0 commit comments