summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_byte_codegen.cpp
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2023-02-21 11:07:43 -0300
committerGeorge Marques <george@gmarqu.es>2023-02-21 11:12:45 -0300
commit0866e6af2d16c48c8e3dcfd6c0b78974f2c11043 (patch)
tree1af9866f3d3c9627c5775ea41df87219377007f0 /modules/gdscript/gdscript_byte_codegen.cpp
parent7e79aead99a53ee7cdf383add9a6a2aea4f15beb (diff)
downloadredot-engine-0866e6af2d16c48c8e3dcfd6c0b78974f2c11043.tar.gz
GDScript: Avoid validated division operation to test for zero
The validated operations for integer division and modulo do not check for division by zero. This avoids validated operation in these cases to make sure the check is performed and avoid crashing the engine.
Diffstat (limited to 'modules/gdscript/gdscript_byte_codegen.cpp')
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index a13bf8009f..5b092e3691 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -581,7 +581,8 @@ void GDScriptByteCodeGenerator::write_unary_operator(const Address &p_target, Va
}
void GDScriptByteCodeGenerator::write_binary_operator(const Address &p_target, Variant::Operator p_operator, const Address &p_left_operand, const Address &p_right_operand) {
- if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand)) {
+ // Avoid validated evaluator for modulo and division when operands are int, since there's no check for division by zero.
+ if (HAS_BUILTIN_TYPE(p_left_operand) && HAS_BUILTIN_TYPE(p_right_operand) && ((p_operator != Variant::OP_DIVIDE && p_operator != Variant::OP_MODULE) || p_left_operand.type.builtin_type != Variant::INT || p_right_operand.type.builtin_type != Variant::INT)) {
if (p_target.mode == Address::TEMPORARY) {
Variant::Type result_type = Variant::get_operator_return_type(p_operator, p_left_operand.type.builtin_type, p_right_operand.type.builtin_type);
Variant::Type temp_type = temporaries[p_target.address].type;