From 47f0cf74608580c822acc97c3c7d7240e8fa5f4d Mon Sep 17 00:00:00 2001 From: LATRio Date: Wed, 6 Oct 2021 18:16:06 +0900 Subject: [PATCH] Add type validations when setting basic type --- core/variant_call.cpp | 4 ++++ modules/visual_script/visual_script_func_nodes.cpp | 3 +++ modules/visual_script/visual_script_nodes.cpp | 1 + 3 files changed, 8 insertions(+) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 09501fe0cdf..e3101b73c50 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1400,6 +1400,7 @@ bool Variant::has_method(const StringName &p_method) const { } Vector Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector()); const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map::Element *E = tf.functions.find(p_method); @@ -1411,6 +1412,7 @@ Vector Variant::get_method_argument_types(Variant::Type p_type, c } bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map::Element *E = tf.functions.find(p_method); @@ -1422,6 +1424,7 @@ bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) } Vector Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector()); const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map::Element *E = tf.functions.find(p_method); @@ -1433,6 +1436,7 @@ Vector Variant::get_method_argument_names(Variant::Type p_type, cons } Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Variant::NIL); const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; const Map::Element *E = tf.functions.find(p_method); diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index c14a46ee5a9..d04a0e335d4 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -282,6 +282,7 @@ String VisualScriptFunctionCall::get_text() const { } void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { + ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX); if (basic_type == p_type) { return; } @@ -1068,6 +1069,7 @@ void VisualScriptPropertySet::_update_base_type() { } } void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { + ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX); if (basic_type == p_type) { return; } @@ -1916,6 +1918,7 @@ VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const } void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { + ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX); if (basic_type == p_type) { return; } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 27f49cfd413..c66eb4d1500 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -1950,6 +1950,7 @@ StringName VisualScriptBasicTypeConstant::get_basic_type_constant() const { } void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) { + ERR_FAIL_INDEX(p_which, Variant::VARIANT_MAX); type = p_which; List constants;