Ver código fonte

Add type validations when setting basic type

LATRio 3 anos atrás
pai
commit
47f0cf7460

+ 4 - 0
core/variant_call.cpp

@@ -1400,6 +1400,7 @@ bool Variant::has_method(const StringName &p_method) const {
 }
 
 Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) {
+	ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<Variant::Type>());
 	const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
 
 	const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
@@ -1411,6 +1412,7 @@ Vector<Variant::Type> 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<StringName, _VariantCall::FuncData>::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<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) {
+	ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, Vector<StringName>());
 	const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
 
 	const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
@@ -1433,6 +1436,7 @@ Vector<StringName> 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<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);

+ 3 - 0
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;
 	}

+ 1 - 0
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<StringName> constants;