From 039a9c5b3465a1c7e028c8941953d8b14295cd0d Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Thu, 4 Dec 2025 21:32:19 +0100 Subject: [PATCH] prevent crash with div 0 and mod 0 --- src/script/context.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/script/context.cpp b/src/script/context.cpp index 610604d7..ebdf43ae 100644 --- a/src/script/context.cpp +++ b/src/script/context.cpp @@ -504,14 +504,16 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP& a = to_script(a->toDouble() / b->toDouble()); break; case I_DIV: - if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { + if (b->toDouble() == 0.0) a = to_script(a->toDouble() / b->toDouble()); + else if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { a = to_script((int)(a->toDouble() / b->toDouble())); } else { a = to_script(a->toInt() / b->toInt()); } break; case I_MOD: - if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { + if (b->toDouble() == 0.0) a = to_script(a->toDouble() / b->toDouble()); + else if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { a = to_script(fmod(a->toDouble(), b->toDouble())); } else { a = to_script(a->toInt() % b->toInt());