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/ --- editor/property_editor.cpp | 70 +++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'editor/property_editor.cpp') diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 1bd748a08..d5d0de537 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -176,7 +176,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { Object *inst = ClassDB::instance(orig_type); - Ref res = Ref(inst->cast_to()); + Ref res = Ref(Object::cast_to(inst)); ERR_FAIL_COND(res.is_null()); @@ -215,8 +215,8 @@ void CustomPropertyEditor::_menu_option(int p_which) { } break; case OBJ_MENU_NEW_SCRIPT: { - if (owner->cast_to()) - EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(owner->cast_to()); + if (Object::cast_to(owner)) + EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to(owner)); } break; case OBJ_MENU_SHOW_IN_FILE_SYSTEM: { @@ -243,7 +243,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { Object *obj = ClassDB::instance(intype); ERR_BREAK(!obj); - Resource *res = obj->cast_to(); + Resource *res = Object::cast_to(obj); ERR_BREAK(!res); if (owner && hint == PROPERTY_HINT_RESOURCE_TYPE && hint_text == "Script") { //make visual script the right type @@ -593,8 +593,8 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: MAKE_PROPSELECT Object *obj = ObjectDB::get_instance(hint_text.to_int64()); - if (obj && obj->cast_to