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/3d/physics_joint.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scene/3d/physics_joint.cpp') diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index 55007c6dc..af6e7f48f 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -55,8 +55,8 @@ void Joint::_update_joint(bool p_only_free) { if (!node_a && !node_b) return; - PhysicsBody *body_a = node_a ? node_a->cast_to() : (PhysicsBody *)NULL; - PhysicsBody *body_b = node_b ? node_b->cast_to() : (PhysicsBody *)NULL; + PhysicsBody *body_a = Object::cast_to(node_a); + PhysicsBody *body_b = Object::cast_to(node_b); if (!body_a && !body_b) return; @@ -1153,8 +1153,8 @@ void PhysicsJoint::_disconnect() { Node *nA = get_node(body_A); Node *nB = get_node(body_B); - PhysicsBody *A = nA?nA->cast_to():NULL; - PhysicsBody *B = nA?nB->cast_to():NULL; + PhysicsBody *A = Object::cast_to(nA); + PhysicsBody *B = Object::cast_to(nB); if (!A ||!B) return; @@ -1173,8 +1173,8 @@ void PhysicsJoint::_connect() { Node *nA = get_node(body_A); Node *nB = get_node(body_B); - PhysicsBody *A = nA?nA->cast_to():NULL; - PhysicsBody *B = nA?nB->cast_to():NULL; + PhysicsBody *A = Object::cast_to(nA); + PhysicsBody *B = Object::cast_to(nB); if (!A && !B) return; -- cgit v1.2.3-70-g09d2