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/ --- scene/gui/popup_menu.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scene/gui/popup_menu.cpp') diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 1ba936c4e..79caf1c83 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -168,7 +168,7 @@ void PopupMenu::_activate_submenu(int over) { Node *n = get_node(items[over].submenu); ERR_EXPLAIN("item subnode does not exist: " + items[over].submenu); ERR_FAIL_COND(!n); - Popup *pm = n->cast_to(); + Popup *pm = Object::cast_to(n); ERR_EXPLAIN("item subnode is not a Popup: " + items[over].submenu); ERR_FAIL_COND(!pm); if (pm->is_visible_in_tree()) @@ -187,7 +187,7 @@ void PopupMenu::_activate_submenu(int over) { pm->set_position(pos); pm->popup(); - PopupMenu *pum = pm->cast_to(); + PopupMenu *pum = Object::cast_to(pm); if (pum) { pr.position -= pum->get_global_position(); @@ -869,7 +869,7 @@ bool PopupMenu::activate_item_by_event(const Ref &p_event, bool p_fo if (!n) continue; - PopupMenu *pm = n->cast_to(); + PopupMenu *pm = Object::cast_to(n); if (!pm) continue; @@ -891,14 +891,14 @@ void PopupMenu::activate_item(int p_item) { //hide all parent PopupMenue's Node *next = get_parent(); - PopupMenu *pop = next->cast_to(); + PopupMenu *pop = Object::cast_to(next); while (pop) { // We close all parents that are chained together, // with hide_on_item_selection enabled if ((items[p_item].checkable && hide_on_checkable_item_selection && pop->is_hide_on_checkable_item_selection()) || (!items[p_item].checkable && hide_on_item_selection && pop->is_hide_on_item_selection())) { pop->hide(); next = next->get_parent(); - pop = next->cast_to(); + pop = Object::cast_to(next); } else { // Break out of loop when the next parent has // hide_on_item_selection disabled -- cgit v1.2.3-70-g09d2