[gnome-software] Do not crash when the list box callback is called with junk



commit 406c3ff783a2c04cf9daf786d1d1ed57d0c2e9a6
Author: Richard Hughes <richard hughsie com>
Date:   Mon Nov 18 10:48:47 2013 +0000

    Do not crash when the list box callback is called with junk
    
    Not sure what's happening here, but crashing isn't the thing to do.

 src/gs-shell-installed.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 29d3b89..12f65e4 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -365,7 +365,7 @@ gs_shell_installed_refresh (GsShellInstalled *shell_installed, gboolean scroll_u
 }
 
 /**
- * gs_shell_installed_sort_func:
+ * gs_shell_installed_get_app_sort_key:
  *
  * Get a sort key to achive this:
  *
@@ -438,20 +438,30 @@ gs_shell_installed_sort_func (GtkListBoxRow *a,
                              GtkListBoxRow *b,
                              gpointer user_data)
 {
-       GsAppWidget *aw1 = GS_APP_WIDGET (gtk_bin_get_child (GTK_BIN (a)));
-       GsAppWidget *aw2 = GS_APP_WIDGET (gtk_bin_get_child (GTK_BIN (b)));
-       GsApp *a1 = gs_app_widget_get_app (aw1);
-       GsApp *a2 = gs_app_widget_get_app (aw2);
-       gchar *key1 = gs_shell_installed_get_app_sort_key (a1);
-       gchar *key2 = gs_shell_installed_get_app_sort_key (a2);
-       gint retval;
+       GsApp *a1, *a2;
+       GsAppWidget *aw1, *aw2;
+       gchar *key1 = NULL;
+       gchar *key2 = NULL;
+       gint retval = 0;
+
+       /* check valid */
+       if (!GTK_IS_BIN(a) || !GTK_IS_BIN(b)) {
+               g_warning ("GtkListBoxRow not valid");
+               goto out;
+       }
+
+       aw1 = GS_APP_WIDGET (gtk_bin_get_child (GTK_BIN (a)));
+       aw2 = GS_APP_WIDGET (gtk_bin_get_child (GTK_BIN (b)));
+       a1 = gs_app_widget_get_app (aw1);
+       a2 = gs_app_widget_get_app (aw2);
+       key1 = gs_shell_installed_get_app_sort_key (a1);
+       key2 = gs_shell_installed_get_app_sort_key (a2);
 
        /* compare the keys according to the algorithm above */
        retval = g_strcmp0 (key1, key2);
-
+out:
        g_free (key1);
        g_free (key2);
-
        return retval;
 }
 


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