[gnome-software] gs-utils: Fix NULL handling in string sorting function



commit 89b9f409c768c52c5899159c46d3feeffe04cbdb
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Dec 10 12:31:33 2019 +0000

    gs-utils: Fix NULL handling in string sorting function
    
    Prior to commit 7da315a0e the code correctly handled apps which returned
    NULL from gs_app_get_name(). Fix that.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    See: !369

 lib/gs-utils.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 92c36d62..9279caca 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -361,19 +361,20 @@ gs_utils_sort_key (const gchar *str)
 
 /**
  * gs_utils_sort_strcmp:
- * @str1: A string to compare
- * @str2: A string to compare
+ * @str1: (nullable): A string to compare
+ * @str2: (nullable): A string to compare
  *
  * Compares two strings in a locale-sensitive, presentational way.
- * Case is ignored and utf8 collation is used (e.g. accents are ignored).
+ * Case is ignored and utf8 collation is used (e.g. accents are ignored). %NULL
+ * is sorted before all non-%NULL strings, and %NULLs compare equal.
  *
  * Returns: < 0 if str1 is before str2, 0 if equal, > 0 if str1 is after str2
  */
 gint
 gs_utils_sort_strcmp (const gchar *str1, const gchar *str2)
 {
-       g_autofree gchar *key1 = gs_utils_sort_key (str1);
-       g_autofree gchar *key2 = gs_utils_sort_key (str2);
+       g_autofree gchar *key1 = (str1 != NULL) ? gs_utils_sort_key (str1) : NULL;
+       g_autofree gchar *key2 = (str2 != NULL) ? gs_utils_sort_key (str2) : NULL;
        return g_strcmp0 (key1, key2);
 }
 


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