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_body.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'scene/3d/physics_body.cpp') diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index 402cd6314..a1bee9a0e 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -116,7 +116,7 @@ bool PhysicsBody::get_collision_layer_bit(int p_bit) const { void PhysicsBody::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - PhysicsBody *physics_body = p_node->cast_to(); + PhysicsBody *physics_body = Object::cast_to(p_node); if (!physics_body) { ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type"); } @@ -127,7 +127,7 @@ void PhysicsBody::add_collision_exception_with(Node *p_node) { void PhysicsBody::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - PhysicsBody *physics_body = p_node->cast_to(); + PhysicsBody *physics_body = Object::cast_to(p_node); if (!physics_body) { ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type"); } @@ -254,7 +254,7 @@ StaticBody::~StaticBody() { void RigidBody::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to() : NULL; + Node *node = Object::cast_to(obj); ERR_FAIL_COND(!node); Map::Element *E = contact_monitor->body_map.find(p_id); @@ -278,7 +278,7 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { void RigidBody::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); - Node *node = obj ? obj->cast_to() : NULL; + Node *node = Object::cast_to(obj); ERR_FAIL_COND(!node); Map::Element *E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); @@ -303,7 +303,7 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); - Node *node = obj ? obj->cast_to() : NULL; + Node *node = Object::cast_to(obj); Map::Element *E = contact_monitor->body_map.find(objid); @@ -369,7 +369,7 @@ void RigidBody::_direct_state_changed(Object *p_state) { //eh.. fuck #ifdef DEBUG_ENABLED - state = p_state->cast_to(); + state = Object::cast_to(p_state); #else state = (PhysicsDirectBodyState *)p_state; //trust it #endif @@ -1105,7 +1105,7 @@ Object *KinematicBody::get_collision_collider_shape(int p_collision) const { ERR_FAIL_INDEX_V(p_collision, colliders.size(), NULL); Object *collider = get_collision_collider(p_collision); if (collider) { - CollisionObject *obj2d = collider->cast_to(); + CollisionObject *obj2d = Object::cast_to(collider); if (obj2d) { uint32_t owner = shape_find_owner(colliders[p_collision].collider_shape); return obj2d->shape_owner_get_owner(owner); -- cgit v1.3.1