mirror of
https://github.com/godotengine/godot.git
synced 2025-10-25 18:54:43 +00:00
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/
This commit is contained in:
parent
4aa2c18cb4
commit
cacced7e50
185 changed files with 1314 additions and 1508 deletions
|
|
@ -371,7 +371,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
|
|||
Object *obj_A = *a;
|
||||
Object *obj_B = *b;
|
||||
|
||||
GDScript *scr_B = obj_B->cast_to<GDScript>();
|
||||
GDScript *scr_B = Object::cast_to<GDScript>(obj_B);
|
||||
|
||||
bool extends_ok = false;
|
||||
|
||||
|
|
@ -397,7 +397,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
|
|||
|
||||
} else {
|
||||
|
||||
GDNativeClass *nc = obj_B->cast_to<GDNativeClass>();
|
||||
GDNativeClass *nc = Object::cast_to<GDNativeClass>(obj_B);
|
||||
|
||||
if (!nc) {
|
||||
|
||||
|
|
@ -1434,7 +1434,7 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount
|
|||
// If the return value is a GDFunctionState reference,
|
||||
// then the function did yield again after resuming.
|
||||
if (ret.is_ref()) {
|
||||
GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>();
|
||||
GDFunctionState *gdfs = Object::cast_to<GDFunctionState>((Object *)&ret);
|
||||
if (gdfs && gdfs->function == function)
|
||||
completed = false;
|
||||
}
|
||||
|
|
@ -1490,7 +1490,7 @@ Variant GDFunctionState::resume(const Variant &p_arg) {
|
|||
// If the return value is a GDFunctionState reference,
|
||||
// then the function did yield again after resuming.
|
||||
if (ret.is_ref()) {
|
||||
GDFunctionState *gdfs = ret.operator Object *()->cast_to<GDFunctionState>();
|
||||
GDFunctionState *gdfs = Object::cast_to<GDFunctionState>((Object *)&ret);
|
||||
if (gdfs && gdfs->function == function)
|
||||
completed = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue