From cacced7e507f7603bacc03ae2616e58f0ede122a Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Thu, 24 Aug 2017 22:58:51 +0200 Subject: Convert Object::cast_to() to the static version Currently we rely on some undefined behavior when Object->cast_to() gets called with a Null pointer. This used to work fine with GCC < 6 but newer versions of GCC remove all codepaths in which the this pointer is Null. However, the non-static cast_to() was supposed to be null safe. This patch makes cast_to() Null safe and removes the now redundant Null checks where they existed. It is explained in this article: https://www.viva64.com/en/b/0226/ --- modules/visual_script/visual_script_yield_nodes.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'modules/visual_script/visual_script_yield_nodes.cpp') diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index df88d2e7f7..958eacf2f2 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -105,7 +105,7 @@ public: } else { //yield - SceneTree *tree = OS::get_singleton()->get_main_loop()->cast_to(); + SceneTree *tree = Object::cast_to(OS::get_singleton()->get_main_loop()); if (!tree) { r_error_str = "Main Loop is not SceneTree"; r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -252,10 +252,7 @@ Node *VisualScriptYieldSignal::_get_base_node() const { return NULL; MainLoop *main_loop = OS::get_singleton()->get_main_loop(); - if (!main_loop) - return NULL; - - SceneTree *scene_tree = main_loop->cast_to(); + SceneTree *scene_tree = Object::cast_to(main_loop); if (!scene_tree) return NULL; @@ -530,7 +527,7 @@ public: } break; case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: { - Node *node = instance->get_owner_ptr()->cast_to(); + Node *node = Object::cast_to(instance->get_owner_ptr()); if (!node) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Base object is not a Node!"; -- cgit v1.2.3