mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
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/
This commit is contained in:
@@ -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 *control = Object::cast_to<Control>(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 *control = Object::cast_to<Control>(_get_tabs()[p_index]);
|
||||
if (!control || control->is_set_as_toplevel())
|
||||
return 0;
|
||||
|
||||
@@ -332,7 +332,7 @@ Vector<Control *> TabContainer::_get_tabs() const {
|
||||
Vector<Control *> controls;
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
|
||||
Control *control = get_child(i)->cast_to<Control>();
|
||||
Control *control = Object::cast_to<Control>(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>();
|
||||
Control *c = Object::cast_to<Control>(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>();
|
||||
popup = Object::cast_to<Popup>(p_popup);
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user