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/plugins/script_editor_plugin.cpp | 162 +++++++++++++++----------------- 1 file changed, 77 insertions(+), 85 deletions(-) (limited to 'editor/plugins/script_editor_plugin.cpp') diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index e8770febd..5b0891e0c 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -256,7 +256,7 @@ ScriptEditor *ScriptEditor::script_editor = NULL; String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) { - //ScriptEditorBase *se=_se->cast_to(); + //ScriptEditorBase *se=Object::cast_to(_se); String val = debugger->get_var_value(p_text); if (val != String()) { @@ -280,7 +280,7 @@ void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) { for (int i = 0; i < tab_container->get_child_count(); i++) { - ScriptEditorBase *se = tab_container->get_child(i)->cast_to(); + ScriptEditorBase *se = Object::cast_to(tab_container->get_child(i)); if (!se) { continue; @@ -305,7 +305,7 @@ void ScriptEditor::_goto_script_line2(int p_line) { if (selected < 0 || selected >= tab_container->get_child_count()) return; - ScriptEditorBase *current = tab_container->get_child(selected)->cast_to(); + ScriptEditorBase *current = Object::cast_to(tab_container->get_child(selected)); if (!current) return; @@ -318,7 +318,7 @@ void ScriptEditor::_goto_script_line(REF p_script, int p_line) { if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) { - Ref