From a01c33c9d05719d8c0c6b93b4072a64b013a73d3 Mon Sep 17 00:00:00 2001 From: Bernhard Liebl Date: Wed, 3 Jan 2018 12:29:58 +0100 Subject: [PATCH] Object class checking on bound method calls --- core/method_bind.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/core/method_bind.h b/core/method_bind.h index 2e5712c3fec..21df65b40d6 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -128,10 +128,36 @@ struct VariantCaster { // Object enum casts must go here VARIANT_ENUM_CAST(Object::ConnectFlags); +template +struct VariantObjectClassChecker { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + return true; + } +}; + +template <> +struct VariantObjectClassChecker { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Node *node = p_variant; + return node || !obj; + } +}; + +template <> +struct VariantObjectClassChecker { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Control *control = p_variant; + return control || !obj; + } +}; + #define CHECK_ARG(m_arg) \ if ((m_arg - 1) < p_arg_count) { \ Variant::Type argtype = get_argument_type(m_arg - 1); \ - if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype)) { \ + if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype) || \ + !VariantObjectClassChecker::check(*p_args[m_arg - 1])) { \ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; \ r_error.argument = m_arg - 1; \ r_error.expected = argtype; \