[gtk/wip/otte/for-master] icontheme: Fix variable mixup leading to crashes



commit c677685c1e923cc9edfd29b9a8caeda325f7bfe8
Author: Benjamin Otte <otte redhat com>
Date:   Fri Sep 17 18:51:59 2021 +0200

    icontheme: Fix variable mixup leading to crashes
    
    Note: Don't have 2 variables named "icon" and "gicon", you will screw
    them up.
    
    reftests included.
    
    Fixes #4269

 gtk/gtkicontheme.c                     | 28 ++++++++++++++--------------
 testsuite/reftests/meson.build         |  4 ++++
 testsuite/reftests/pixbuf-icon.ref.ui  | 13 +++++++++++++
 testsuite/reftests/pixbuf-icon.ui      | 16 ++++++++++++++++
 testsuite/reftests/texture-icon.ref.ui | 13 +++++++++++++
 testsuite/reftests/texture-icon.ui     | 16 ++++++++++++++++
 6 files changed, 76 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 1c2d83125c..154c9d8794 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -4109,7 +4109,7 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme       *self,
                                 GtkTextDirection    direction,
                                 GtkIconLookupFlags  flags)
 {
-  GtkIconPaintable *icon = NULL;
+  GtkIconPaintable *paintable = NULL;
 
   g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
   g_return_val_if_fail (G_IS_ICON (gicon), NULL);
@@ -4123,42 +4123,42 @@ gtk_icon_theme_lookup_by_gicon (GtkIconTheme       *self,
 
   if (GDK_IS_TEXTURE (gicon))
     {
-      icon = icon_paintable_new (NULL, size, scale);
-      icon->texture = g_object_ref (GDK_TEXTURE (icon));
+      paintable = icon_paintable_new (NULL, size, scale);
+      paintable->texture = g_object_ref (GDK_TEXTURE (gicon));
     }
   else if (GDK_IS_PIXBUF (gicon))
     {
-      icon = icon_paintable_new (NULL, size, scale);
-      icon->texture = gdk_texture_new_for_pixbuf (GDK_PIXBUF (icon));
+      paintable = icon_paintable_new (NULL, size, scale);
+      paintable->texture = gdk_texture_new_for_pixbuf (GDK_PIXBUF (gicon));
     }
   else if (G_IS_FILE_ICON (gicon))
     {
       GFile *file = g_file_icon_get_file (G_FILE_ICON (gicon));
 
-      icon = gtk_icon_paintable_new_for_file (file, size, scale);
+      paintable = gtk_icon_paintable_new_for_file (file, size, scale);
     }
   else if (G_IS_LOADABLE_ICON (gicon))
     {
-      icon = icon_paintable_new (NULL, size, scale);
-      icon->loadable = G_LOADABLE_ICON (g_object_ref (gicon));
-      icon->is_svg = FALSE;
+      paintable = icon_paintable_new (NULL, size, scale);
+      paintable->loadable = G_LOADABLE_ICON (g_object_ref (gicon));
+      paintable->is_svg = FALSE;
     }
   else if (G_IS_THEMED_ICON (gicon))
     {
       const char **names;
 
       names = (const char **) g_themed_icon_get_names (G_THEMED_ICON (gicon));
-      icon = gtk_icon_theme_lookup_icon (self, names[0], &names[1], size, scale, direction, flags);
+      paintable = gtk_icon_theme_lookup_icon (self, names[0], &names[1], size, scale, direction, flags);
     }
   else
     {
       g_debug ("Unhandled GIcon type %s", G_OBJECT_TYPE_NAME (gicon));
-      icon = icon_paintable_new ("image-missing", size, scale);
-      icon->filename = g_strdup (IMAGE_MISSING_RESOURCE_PATH);
-      icon->is_resource = TRUE;
+      paintable = icon_paintable_new ("image-missing", size, scale);
+      paintable->filename = g_strdup (IMAGE_MISSING_RESOURCE_PATH);
+      paintable->is_resource = TRUE;
     }
 
-  return icon;
+  return paintable;
 }
 
 /**
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index a7c295137e..5e4d5d08d7 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -370,6 +370,8 @@ testdata = [
   'partial-rounded-border.ui',
   'picture-load-invalid-file.ui',
   'picture-load-invalid-file.ref.ui',
+  'pixbuf-icon.ref.ui',
+  'pixbuf-icon.ui',
   'pseudoclass-on-box.css',
   'pseudoclass-on-box.ref.ui',
   'pseudoclass-on-box.ui',
@@ -423,6 +425,8 @@ testdata = [
   'symbolic-icon-translucent-color.css',
   'symbolic-icon-translucent-color.ref.ui',
   'symbolic-icon-translucent-color.ui',
+  'texture-icon.ref.ui',
+  'texture-icon.ui',
   'textview-border-windows.css',
   'textview-border-windows.ref.ui',
   'textview-border-windows.ui',
diff --git a/testsuite/reftests/pixbuf-icon.ref.ui b/testsuite/reftests/pixbuf-icon.ref.ui
new file mode 100644
index 0000000000..5120db1573
--- /dev/null
+++ b/testsuite/reftests/pixbuf-icon.ref.ui
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">10</property>
+    <property name="height_request">10</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkImage">
+        <property name="paintable">resource:///org/gtk/libgtk/icons/16x16/status/image-missing.png</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/pixbuf-icon.ui b/testsuite/reftests/pixbuf-icon.ui
new file mode 100644
index 0000000000..86938256f8
--- /dev/null
+++ b/testsuite/reftests/pixbuf-icon.ui
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkCellRendererPixbuf" id="just-creating-a-pixbuf">
+    <property 
name="pixbuf-expander-open">resource:///org/gtk/libgtk/icons/16x16/status/image-missing.png</property>
+  </object>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">10</property>
+    <property name="height_request">10</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkImage">
+        <property name="gicon" bind-source="just-creating-a-pixbuf" bind-property="pixbuf-expander-open" 
bind-flags="sync-create"/>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/texture-icon.ref.ui b/testsuite/reftests/texture-icon.ref.ui
new file mode 100644
index 0000000000..5120db1573
--- /dev/null
+++ b/testsuite/reftests/texture-icon.ref.ui
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">10</property>
+    <property name="height_request">10</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkImage">
+        <property name="paintable">resource:///org/gtk/libgtk/icons/16x16/status/image-missing.png</property>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/texture-icon.ui b/testsuite/reftests/texture-icon.ui
new file mode 100644
index 0000000000..99c6b9609f
--- /dev/null
+++ b/testsuite/reftests/texture-icon.ui
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <object class="GtkImage" id="just-creating-a-texture">
+    <property name="paintable">resource:///org/gtk/libgtk/icons/16x16/status/image-missing.png</property>
+  </object>
+  <object class="GtkWindow" id="window1">
+    <property name="width_request">10</property>
+    <property name="height_request">10</property>
+    <property name="decorated">0</property>
+    <child>
+      <object class="GtkImage">
+        <property name="gicon" bind-source="just-creating-a-texture" bind-property="paintable" 
bind-flags="sync-create"/>
+      </object>
+    </child>
+  </object>
+</interface>


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