[gnome-software] ui: Fix various calls to gs_utils_sort_key(NULL)



commit 014f0a2b4a8a5a28af76a051b8a60c4530a936e2
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Apr 21 16:52:04 2020 +0100

    ui: Fix various calls to gs_utils_sort_key(NULL)
    
    It causes a critical warning. `gs_app_get_name()` can legitimately
    return `NULL`, so guard against that situation (at the possible expense
    of some less-than-ideal sorting).
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 src/gs-extras-page.c     | 6 ++++--
 src/gs-installed-page.c  | 6 ++++--
 src/gs-removal-dialog.c  | 7 ++++++-
 src/gs-repos-dialog.c    | 8 ++++++--
 src/gs-updates-section.c | 6 ++++--
 5 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/src/gs-extras-page.c b/src/gs-extras-page.c
index c8900c25..946b5a8e 100644
--- a/src/gs-extras-page.c
+++ b/src/gs-extras-page.c
@@ -1072,8 +1072,10 @@ get_app_sort_key (GsApp *app)
        }
 
        /* finally, sort by short name */
-       sort_name = gs_utils_sort_key (gs_app_get_name (app));
-       g_string_append (key, sort_name);
+       if (gs_app_get_name (app) != NULL) {
+               sort_name = gs_utils_sort_key (gs_app_get_name (app));
+               g_string_append (key, sort_name);
+       }
 
        return g_string_free (key, FALSE);
 }
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index 1496a501..de8a8874 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -376,8 +376,10 @@ gs_installed_page_get_app_sort_key (GsApp *app)
                g_string_append (key, "2:");
 
        /* finally, sort by short name */
-       sort_name = gs_utils_sort_key (gs_app_get_name (app));
-       g_string_append (key, sort_name);
+       if (gs_app_get_name (app) != NULL) {
+               sort_name = gs_utils_sort_key (gs_app_get_name (app));
+               g_string_append (key, sort_name);
+       }
 
        return g_string_free (key, FALSE);
 }
diff --git a/src/gs-removal-dialog.c b/src/gs-removal-dialog.c
index b037a243..a901536e 100644
--- a/src/gs-removal-dialog.c
+++ b/src/gs-removal-dialog.c
@@ -51,6 +51,7 @@ add_app (GtkListBox *listbox, GsApp *app)
        GtkWidget *box;
        GtkWidget *widget;
        GtkWidget *row;
+       g_autofree gchar *sort_key = NULL;
 
        box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
        gtk_widget_set_margin_top (box, 12);
@@ -63,9 +64,13 @@ add_app (GtkListBox *listbox, GsApp *app)
        gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END);
        gtk_container_add (GTK_CONTAINER (box), widget);
 
+       if (gs_app_get_name (app) != NULL) {
+               sort_key = gs_utils_sort_key (gs_app_get_name (app));
+       }
+
        g_object_set_data_full (G_OBJECT (box),
                                "sort",
-                               gs_utils_sort_key (gs_app_get_name (app)),
+                               g_steal_pointer (&sort_key),
                                g_free);
 
        gtk_list_box_prepend (listbox, box);
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index 748850c6..93830308 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -687,8 +687,12 @@ get_row_sort_key (GtkListBoxRow *row)
                app = gs_repo_row_get_repo (GS_REPO_ROW (row));
        }
 
-       sort_key = gs_utils_sort_key (gs_app_get_name (app));
-       return g_strdup_printf ("%u:%s", sort_order, sort_key);
+       if (gs_app_get_name (app) != NULL) {
+               sort_key = gs_utils_sort_key (gs_app_get_name (app));
+               return g_strdup_printf ("%u:%s", sort_order, sort_key);
+       } else {
+               return g_strdup_printf ("%u:", sort_order);
+       }
 }
 
 static gint
diff --git a/src/gs-updates-section.c b/src/gs-updates-section.c
index a3d6b893..b47f54e3 100644
--- a/src/gs-updates-section.c
+++ b/src/gs-updates-section.c
@@ -171,8 +171,10 @@ _get_app_sort_key (GsApp *app)
        }
 
        /* finally, sort by short name */
-       sort_name = gs_utils_sort_key (gs_app_get_name (app));
-       g_string_append (key, sort_name);
+       if (gs_app_get_name (app) != NULL) {
+               sort_name = gs_utils_sort_key (gs_app_get_name (app));
+               g_string_append (key, sort_name);
+       }
 
        return g_string_free (key, FALSE);
 }


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