From 4b3f87718d7fc9e3117288cffc52e71a42b83871 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 16 Dec 2025 15:07:29 +0300 Subject: [PATCH] Check for division by zero in interpreter --- libs/interpreter/source/eval.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/interpreter/source/eval.cpp b/libs/interpreter/source/eval.cpp index 21a945f..8079cc4 100644 --- a/libs/interpreter/source/eval.cpp +++ b/libs/interpreter/source/eval.cpp @@ -178,12 +178,22 @@ namespace pslang::interpreter case ast::binary_operation_type::division: if constexpr (!std::is_same_v) { + if constexpr (std::is_integral_v) + { + if (arg2.value == static_cast(0)) + throw std::runtime_error("Division by zero"); + } return primitive_value(primitive_value_base{static_cast(arg1.value / arg2.value)}); } break; case ast::binary_operation_type::remainder: if constexpr (!std::is_same_v && std::is_integral_v) { + if constexpr (std::is_integral_v) + { + if (arg2.value == static_cast(0)) + throw std::runtime_error("Division by zero"); + } return primitive_value(primitive_value_base{static_cast(arg1.value % arg2.value)}); } break;