File tree 1 file changed +14
-2
lines changed
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,
240
240
}
241
241
FiExpr;
242
242
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;
244
250
}
245
251
FiExpr;
246
252
IfExpr (Mul, v) {
@@ -252,7 +258,13 @@ VIntS evaluate(const std::shared_ptr<Expr> &expr,
252
258
}
253
259
FiExpr;
254
260
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;
256
268
}
257
269
FiExpr;
258
270
IfExpr (And, v) {
You can’t perform that action at this time.
0 commit comments