lab2 feat: prevent division by zero in non-folded operations

This commit is contained in:
2026-10-15 10:16:01 +03:00
parent 0329ed8326
commit b15ae562fd
2 changed files with 8 additions and 0 deletions
+1
View File
@@ -6,3 +6,4 @@
#define MAX_TOKEN_STRING_LEN 256 #define MAX_TOKEN_STRING_LEN 256
#define LAB2_EXCLUDE_COMPTIME_OP_WRITES 1 #define LAB2_EXCLUDE_COMPTIME_OP_WRITES 1
#define LAB2_PREVENT_NON_FOLDED_DIV_BY_ZERO 1
+7
View File
@@ -334,6 +334,13 @@ static int write_operation(
} }
else else
{ {
#endif
#if LAB2_PREVENT_NON_FOLDED_DIV_BY_ZERO == 1
if (r.t == Expression::Token::CONST && r.v.d == 0.0 && o.v.o == Expression::Token::DIV)
{
pr_warn("Right operand is zero, operation will raise exception during runtime");
return 1;
}
#endif #endif
int this_op_weight = get_operator_weight(mv, location) + 1; int this_op_weight = get_operator_weight(mv, location) + 1;