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/editor_audio_buses.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'editor/editor_audio_buses.cpp') diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 282055be4..3494aa577 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -376,7 +376,7 @@ void EditorAudioBus::_effect_add(int p_which) { Object *fx = ClassDB::instance(name); ERR_FAIL_COND(!fx); - AudioEffect *afx = fx->cast_to(); + AudioEffect *afx = Object::cast_to(fx); ERR_FAIL_COND(!afx); Ref afxr = Ref(afx); @@ -865,7 +865,7 @@ void EditorAudioBuses::_update_sends() { void EditorAudioBuses::_delete_bus(Object *p_which) { - EditorAudioBus *bus = p_which->cast_to(); + EditorAudioBus *bus = Object::cast_to(p_which); int index = bus->get_index(); if (index == 0) { EditorNode::get_singleton()->show_warning("Master bus can't be deleted!"); @@ -922,7 +922,7 @@ void EditorAudioBuses::_request_drop_end() { drop_end = memnew(EditorAudioBusDrop); bus_hb->add_child(drop_end); - drop_end->set_custom_minimum_size(bus_hb->get_child(0)->cast_to()->get_size()); + drop_end->set_custom_minimum_size(Object::cast_to(bus_hb->get_child(0))->get_size()); drop_end->connect("dropped", this, "_drop_at_index", varray(), CONNECT_DEFERRED); } } @@ -1158,9 +1158,9 @@ void EditorAudioBuses::open_layout(const String &p_path) { void AudioBusesEditorPlugin::edit(Object *p_node) { - if (p_node->cast_to()) { + if (Object::cast_to(p_node)) { - String path = p_node->cast_to()->get_path(); + String path = Object::cast_to(p_node)->get_path(); if (path.is_resource_file()) { audio_bus_editor->open_layout(path); } @@ -1169,7 +1169,7 @@ void AudioBusesEditorPlugin::edit(Object *p_node) { bool AudioBusesEditorPlugin::handles(Object *p_node) const { - return (p_node->cast_to() != NULL); + return (Object::cast_to(p_node) != NULL); } void AudioBusesEditorPlugin::make_visible(bool p_visible) { -- cgit v1.2.3-70-g09d2