[glib] Do not crash when checking whether an instance type is of a given fundamental.



commit 4b5bdf6cebc4c1b7c6db7e23c678cc2f5003e757
Author: Andre Moreira Magalhaes (andrunko) <andre magalhaes collabora co uk>
Date:   Tue Jul 29 21:04:48 2014 -0300

    Do not crash when checking whether an instance type is of a given fundamental.
    
    Not all instances have a TypeNode associated (e.g. GstEvent), so lets check if node is available
    before trying to use it.
    
    This crash can be easily reproduced by creating an event with gst_event_new_eos and using
    G_IS_OBJECT on the event instance.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733982

 gobject/gtype.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/gobject/gtype.c b/gobject/gtype.c
index 9e60a1e..f766ffd 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -3972,9 +3972,11 @@ gboolean
 g_type_check_instance_is_fundamentally_a (GTypeInstance *type_instance,
                                           GType          fundamental_type)
 {
+  TypeNode *node;
   if (!type_instance || !type_instance->g_class)
     return FALSE;
-  return NODE_FUNDAMENTAL_TYPE(lookup_type_node_I (type_instance->g_class->g_type)) == fundamental_type;
+  node = lookup_type_node_I (type_instance->g_class->g_type);
+  return node && (NODE_FUNDAMENTAL_TYPE(node) == fundamental_type);
 }
 
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]