From b15ae562fd3a6f5f9ecd85a133ce729c3d8bb22d Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Thu, 15 Oct 2026 10:16:01 +0300 Subject: [PATCH] lab2 feat: prevent division by zero in non-folded operations --- config.h | 1 + src/syntaxer.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/config.h b/config.h index 334a266..8747f64 100644 --- a/config.h +++ b/config.h @@ -6,3 +6,4 @@ #define MAX_TOKEN_STRING_LEN 256 #define LAB2_EXCLUDE_COMPTIME_OP_WRITES 1 +#define LAB2_PREVENT_NON_FOLDED_DIV_BY_ZERO 1 diff --git a/src/syntaxer.cpp b/src/syntaxer.cpp index a4ad568..de1d372 100644 --- a/src/syntaxer.cpp +++ b/src/syntaxer.cpp @@ -334,6 +334,13 @@ static int write_operation( } 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 int this_op_weight = get_operator_weight(mv, location) + 1;