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/tab_container.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'scene/gui/tab_container.cpp') diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index d32b899de..8afcc896a 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -230,7 +230,7 @@ void TabContainer::_notification(int p_what) { tab_style->draw(canvas, tab_rect); // Draw the tab contents. - Control *control = tabs[i + first_tab_cache]->cast_to(); + Control *control = Object::cast_to(tabs[i + first_tab_cache]); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name()); int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT); @@ -293,7 +293,7 @@ void TabContainer::_notification(int p_what) { } int TabContainer::_get_tab_width(int p_index) const { - Control *control = _get_tabs()[p_index]->cast_to(); + Control *control = Object::cast_to(_get_tabs()[p_index]); if (!control || control->is_set_as_toplevel()) return 0; @@ -332,7 +332,7 @@ Vector TabContainer::_get_tabs() const { Vector controls; for (int i = 0; i < get_child_count(); i++) { - Control *control = get_child(i)->cast_to(); + Control *control = Object::cast_to(get_child(i)); if (!control || control->is_toplevel_control()) continue; @@ -350,7 +350,7 @@ void TabContainer::add_child_notify(Node *p_child) { Control::add_child_notify(p_child); - Control *c = p_child->cast_to(); + Control *c = Object::cast_to(p_child); if (!c) return; if (c->is_set_as_toplevel()) @@ -616,7 +616,7 @@ Size2 TabContainer::get_minimum_size() const { void TabContainer::set_popup(Node *p_popup) { ERR_FAIL_NULL(p_popup); - popup = p_popup->cast_to(); + popup = Object::cast_to(p_popup); update(); } -- cgit v1.2.3-70-g09d2