diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2017-08-24 22:58:51 +0200 |
---|---|---|
committer | Hein-Pieter van Braam <hp@tmm.cx> | 2017-08-24 23:08:24 +0200 |
commit | cacced7e507f7603bacc03ae2616e58f0ede122a (patch) | |
tree | 7af89373e86cd1a7af6ea04e10280084cabb7144 /scene/main/node.cpp | |
parent | 4aa2c18cb428ffde05c67987926736a9ca62703b (diff) | |
download | redot-engine-cacced7e507f7603bacc03ae2616e58f0ede122a.tar.gz |
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/
Diffstat (limited to 'scene/main/node.cpp')
-rwxr-xr-x | scene/main/node.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index c850a5ae74..66d3ad22f1 100755 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -194,7 +194,7 @@ void Node::_propagate_enter_tree() { data.depth = 1; } - data.viewport = cast_to<Viewport>(); + data.viewport = Object::cast_to<Viewport>(this); if (!data.viewport) data.viewport = data.parent->data.viewport; @@ -2160,9 +2160,9 @@ Node *Node::_duplicate(int p_flags) const { bool instanced = false; - if (cast_to<InstancePlaceholder>()) { + if (Object::cast_to<InstancePlaceholder>(this)) { - const InstancePlaceholder *ip = cast_to<const InstancePlaceholder>(); + const InstancePlaceholder *ip = Object::cast_to<const InstancePlaceholder>(this); InstancePlaceholder *nip = memnew(InstancePlaceholder); nip->set_instance_path(ip->get_instance_path()); node = nip; @@ -2180,7 +2180,7 @@ Node *Node::_duplicate(int p_flags) const { Object *obj = ClassDB::instance(get_class()); ERR_FAIL_COND_V(!obj, NULL); - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); ERR_FAIL_COND_V(!node, NULL); @@ -2270,7 +2270,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p print_line("could not duplicate: " + String(get_class())); } ERR_FAIL_COND(!obj); - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); } @@ -2326,7 +2326,7 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { NodePath p = p_original->get_path_to(this); Node *copy = p_copy->get_node(p); - Node *target = E->get().target->cast_to<Node>(); + Node *target = Object::cast_to<Node>(E->get().target); if (!target) { continue; } @@ -2355,7 +2355,7 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { print_line("could not duplicate: " + String(get_class())); } ERR_FAIL_COND_V(!obj, NULL); - node = obj->cast_to<Node>(); + node = Object::cast_to<Node>(obj); if (!node) memdelete(obj); ERR_FAIL_COND_V(!node, NULL); @@ -2610,7 +2610,7 @@ void Node::_set_tree(SceneTree *p_tree) { static void _Node_debug_sn(Object *p_obj) { - Node *n = p_obj->cast_to<Node>(); + Node *n = Object::cast_to<Node>(p_obj); if (!n) return; |