[gtk+] Avoid an a crash with GTK_DEBUG=builder



commit 2cabfcc80100b1863e82439e7b39eed024eb3a24
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 26 14:47:16 2016 -0500

    Avoid an a crash with GTK_DEBUG=builder
    
    We might cast objects to GtkBuildable even if they aren't,
    to print their names. Don't do that.
    
    Found by gcc's address sanitizer.

 gtk/gtkbuilder.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index f742374..1b7a0f9 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -541,6 +541,15 @@ gtk_builder_get_parameters (GtkBuilder  *builder,
     }
 }
 
+static const gchar *
+object_get_name (GObject *object)
+{
+  if (GTK_IS_BUILDABLE (object))
+    return gtk_buildable_get_name (GTK_BUILDABLE (object));
+  else
+    return g_object_get_data (object, "gtk-builder-name");
+}
+
 static GObject *
 gtk_builder_get_internal_child (GtkBuilder   *builder,
                                 ObjectInfo   *info,
@@ -561,7 +570,7 @@ gtk_builder_get_internal_child (GtkBuilder   *builder,
       GTK_NOTE (BUILDER,
                 g_print ("Trying to get internal child %s from %s\n",
                          childname,
-                         gtk_buildable_get_name (GTK_BUILDABLE (info->object))));
+                         object_get_name (info->object)));
 
       if (GTK_IS_BUILDABLE (info->object))
           obj = gtk_buildable_get_internal_child (GTK_BUILDABLE (info->object),
@@ -850,8 +859,7 @@ _gtk_builder_add (GtkBuilder *builder,
 
   if (!child_info->parent)
     {
-      g_warning ("%s: Not adding, No parent",
-                 gtk_buildable_get_name (GTK_BUILDABLE (object)));
+      g_warning ("%s: Not adding, No parent", object_get_name (object));
       return;
     }
 
@@ -861,9 +869,7 @@ _gtk_builder_add (GtkBuilder *builder,
   g_assert (GTK_IS_BUILDABLE (parent));
 
   GTK_NOTE (BUILDER,
-            g_print ("adding %s to %s\n",
-                     gtk_buildable_get_name (GTK_BUILDABLE (object)),
-                     gtk_buildable_get_name (GTK_BUILDABLE (parent))));
+            g_print ("adding %s to %s\n", object_get_name (object), object_get_name (parent)));
 
   gtk_buildable_add_child (GTK_BUILDABLE (parent), builder, object,
                            child_info->type);


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