prevent crash with div 0 and mod 0

This commit is contained in:
GenevensiS
2025-12-04 21:32:19 +01:00
parent 4e197a75cb
commit 039a9c5b34
+4 -2
View File
@@ -504,14 +504,16 @@ void instrBinary (BinaryInstructionType i, ScriptValueP& a, const ScriptValueP&
a = to_script(a->toDouble() / b->toDouble()); a = to_script(a->toDouble() / b->toDouble());
break; break;
case I_DIV: 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())); a = to_script((int)(a->toDouble() / b->toDouble()));
} else { } else {
a = to_script(a->toInt() / b->toInt()); a = to_script(a->toInt() / b->toInt());
} }
break; break;
case I_MOD: 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())); a = to_script(fmod(a->toDouble(), b->toDouble()));
} else { } else {
a = to_script(a->toInt() % b->toInt()); a = to_script(a->toInt() % b->toInt());