From 8646fb448705c1893835af2e8b2d9a08b5679df7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 2 Mar 2021 22:55:23 +0100 Subject: [PATCH] patterns: Prevent division by zero --- plugins/libimhex/source/lang/evaluator.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/libimhex/source/lang/evaluator.cpp b/plugins/libimhex/source/lang/evaluator.cpp index adcc7d396..7ec01a486 100644 --- a/plugins/libimhex/source/lang/evaluator.cpp +++ b/plugins/libimhex/source/lang/evaluator.cpp @@ -232,8 +232,12 @@ namespace hex::lang { case Token::Operator::Star: return new ASTNodeIntegerLiteral({ newType, leftValue * rightValue }); case Token::Operator::Slash: + if (rightValue == 0) + this->getConsole().abortEvaluation("Division by zero"); return new ASTNodeIntegerLiteral({ newType, leftValue / rightValue }); case Token::Operator::Percent: + if (rightValue == 0) + this->getConsole().abortEvaluation("Division by zero"); return new ASTNodeIntegerLiteral({ newType, modulus(leftValue, rightValue) }); case Token::Operator::ShiftLeft: return new ASTNodeIntegerLiteral({ newType, shiftLeft(leftValue, rightValue) });