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/project_manager.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'editor/project_manager.cpp') diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 6ace79df2..c84780739 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -475,7 +475,7 @@ void ProjectManager::_notification(int p_what) { void ProjectManager::_panel_draw(Node *p_hb) { - HBoxContainer *hb = p_hb->cast_to(); + HBoxContainer *hb = Object::cast_to(p_hb); hb->draw_line(Point2(0, hb->get_size().y + 1), Point2(hb->get_size().x - 10, hb->get_size().y + 1), get_color("guide_color", "Tree")); @@ -487,7 +487,7 @@ void ProjectManager::_panel_draw(Node *p_hb) { void ProjectManager::_update_project_buttons() { for (int i = 0; i < scroll_childs->get_child_count(); i++) { - CanvasItem *item = scroll_childs->get_child(i)->cast_to(); + CanvasItem *item = Object::cast_to(scroll_childs->get_child(i)); item->update(); } @@ -509,7 +509,7 @@ void ProjectManager::_panel_input(const Ref &p_ev, Node *p_hb) { int clicked_id = -1; int last_clicked_id = -1; for (int i = 0; i < scroll_childs->get_child_count(); i++) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); + HBoxContainer *hb = Object::cast_to(scroll_childs->get_child(i)); if (!hb) continue; if (hb->get_meta("name") == clicked) clicked_id = i; if (hb->get_meta("name") == last_clicked) last_clicked_id = i; @@ -519,7 +519,7 @@ void ProjectManager::_panel_input(const Ref &p_ev, Node *p_hb) { int min = clicked_id < last_clicked_id ? clicked_id : last_clicked_id; int max = clicked_id > last_clicked_id ? clicked_id : last_clicked_id; for (int i = 0; i < scroll_childs->get_child_count(); ++i) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); + HBoxContainer *hb = Object::cast_to(scroll_childs->get_child(i)); if (!hb) continue; if (i != clicked_id && (i < min || i > max) && !mb->get_control()) { selected_list.erase(hb->get_meta("name")); @@ -572,7 +572,7 @@ void ProjectManager::_unhandled_input(const Ref &p_ev) { for (int i = 0; i < scroll_childs->get_child_count(); i++) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); + HBoxContainer *hb = Object::cast_to(scroll_childs->get_child(i)); if (hb) { selected_list.clear(); selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene")); @@ -587,7 +587,7 @@ void ProjectManager::_unhandled_input(const Ref &p_ev) { for (int i = scroll_childs->get_child_count() - 1; i >= 0; i--) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); + HBoxContainer *hb = Object::cast_to(scroll_childs->get_child(i)); if (hb) { selected_list.clear(); selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene")); @@ -609,7 +609,7 @@ void ProjectManager::_unhandled_input(const Ref &p_ev) { for (int i = scroll_childs->get_child_count() - 1; i >= 0; i--) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); + HBoxContainer *hb = Object::cast_to(scroll_childs->get_child(i)); if (!hb) continue; String current = hb->get_meta("name"); @@ -646,7 +646,7 @@ void ProjectManager::_unhandled_input(const Ref &p_ev) { for (int i = 0; i < scroll_childs->get_child_count(); i++) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); + HBoxContainer *hb = Object::cast_to(scroll_childs->get_child(i)); if (!hb) continue; String current = hb->get_meta("name"); @@ -885,8 +885,8 @@ void ProjectManager::_load_recent_projects() { void ProjectManager::_on_project_created(const String &dir) { bool has_already = false; for (int i = 0; i < scroll_childs->get_child_count(); i++) { - HBoxContainer *hb = scroll_childs->get_child(i)->cast_to(); - Label *fpath = hb->get_node(NodePath("project/path"))->cast_to