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/ --- core/undo_redo.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'core/undo_redo.cpp') diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index bb7014639..00a468816 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -111,8 +111,8 @@ void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_A ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - do_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + do_op.resref = Ref(Object::cast_to(p_object)); do_op.type = Operation::TYPE_METHOD; do_op.name = p_method; @@ -135,8 +135,8 @@ void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - undo_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + undo_op.resref = Ref(Object::cast_to(p_object)); undo_op.type = Operation::TYPE_METHOD; undo_op.name = p_method; @@ -152,8 +152,8 @@ void UndoRedo::add_do_property(Object *p_object, const String &p_property, const ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - do_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + do_op.resref = Ref(Object::cast_to(p_object)); do_op.type = Operation::TYPE_PROPERTY; do_op.name = p_property; @@ -171,8 +171,8 @@ void UndoRedo::add_undo_property(Object *p_object, const String &p_property, con Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - undo_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + undo_op.resref = Ref(Object::cast_to(p_object)); undo_op.type = Operation::TYPE_PROPERTY; undo_op.name = p_property; @@ -185,8 +185,8 @@ void UndoRedo::add_do_reference(Object *p_object) { ERR_FAIL_COND((current_action + 1) >= actions.size()); Operation do_op; do_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - do_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + do_op.resref = Ref(Object::cast_to(p_object)); do_op.type = Operation::TYPE_REFERENCE; actions[current_action + 1].do_ops.push_back(do_op); @@ -202,8 +202,8 @@ void UndoRedo::add_undo_reference(Object *p_object) { Operation undo_op; undo_op.object = p_object->get_instance_id(); - if (p_object->cast_to()) - undo_op.resref = Ref(p_object->cast_to()); + if (Object::cast_to(p_object)) + undo_op.resref = Ref(Object::cast_to(p_object)); undo_op.type = Operation::TYPE_REFERENCE; actions[current_action + 1].undo_ops.push_back(undo_op); @@ -270,7 +270,7 @@ void UndoRedo::_process_operation_list(List::Element *E) { obj->call(op.name, VARIANT_ARGS_FROM_ARRAY(op.args)); #ifdef TOOLS_ENABLED - Resource *res = obj->cast_to(); + Resource *res = Object::cast_to(obj); if (res) res->set_edited(true); @@ -284,7 +284,7 @@ void UndoRedo::_process_operation_list(List::Element *E) { obj->set(op.name, op.args[0]); #ifdef TOOLS_ENABLED - Resource *res = obj->cast_to(); + Resource *res = Object::cast_to(obj); if (res) res->set_edited(true); #endif -- cgit v1.2.3-70-g09d2