[gthumb] location dialog: do not crash if the file name is not set



commit 2f32deae212ead5bd3b3a5b04f19cb417e4062a2
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Mar 26 17:54:16 2012 +0200

    location dialog: do not crash if the file name is not set

 gthumb/dlg-location.c |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/gthumb/dlg-location.c b/gthumb/dlg-location.c
index 3a17890..91037ba 100644
--- a/gthumb/dlg-location.c
+++ b/gthumb/dlg-location.c
@@ -215,23 +215,34 @@ ok_button_clicked_cb (GtkWidget  *widget,
 }
 
 
-
 static int
 file_data_compare_by_name (gconstpointer  a,
 			   gconstpointer  b)
 {
 	GthFileData *fa = (GthFileData *) a;
 	GthFileData *fb = (GthFileData *) b;
-	char        *sa;
-	char        *sb;
+	const char  *namea;
+	const char  *nameb;
 	int          result;
 
-	sa = g_utf8_collate_key_for_filename (g_file_info_get_name (fa->info), -1);
-	sb = g_utf8_collate_key_for_filename (g_file_info_get_name (fb->info), -1);
-	result = strcmp (sa, sb);
+	namea = g_file_info_get_name (fa->info);
+	nameb = g_file_info_get_name (fb->info);
+	if ((namea == NULL) || (nameb == NULL)) {
+		if ((namea == NULL) && (nameb == NULL))
+			return 0;
+		else if (namea == NULL)
+			return -1;
+		else
+			return 1;
+	}
+	else {
+		char *sa = g_utf8_collate_key_for_filename (namea, -1);
+		char *sb = g_utf8_collate_key_for_filename (nameb, -1);
+		result = strcmp (sa, sb);
 
-	g_free (sa);
-	g_free (sb);
+		g_free (sa);
+		g_free (sb);
+	}
 
 	return result;
 }



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