pidgin: 5c2fa266: Don't allow NULL sort method IDs and don...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Mon Jul 20 21:55:35 EDT 2009


-----------------------------------------------------------------
Revision: 5c2fa26692e9b3bd7503cc82d451386d5078319d
Ancestor: 27d62034c01c4cf6cf8e183e38dda8eaabe453f1
Author: darkrain42 at pidgin.im
Date: 2009-07-20T18:44:07
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5c2fa26692e9b3bd7503cc82d451386d5078319d

Modified files:
        pidgin/gtkblist.c

ChangeLog: 

Don't allow NULL sort method IDs and don't crash on them. Fixes #9658.

I don't know what was generating the NULL id, but this should
keep it from happening again and fix the issue.

-------------- next part --------------
============================================================
--- pidgin/gtkblist.c	aeb9023162fc47adb8d5c5db3a4c20818350272c
+++ pidgin/gtkblist.c	17e22195506b99466024a90546a8fb9660ca48f9
@@ -4642,13 +4642,21 @@ void pidgin_blist_setup_sort_methods()
 
 void pidgin_blist_setup_sort_methods()
 {
+	const char *id;
+
 	pidgin_blist_sort_method_reg("none", _("Manually"), sort_method_none);
 #if GTK_CHECK_VERSION(2,2,1)
 	pidgin_blist_sort_method_reg("alphabetical", _("Alphabetically"), sort_method_alphabetical);
 	pidgin_blist_sort_method_reg("status", _("By status"), sort_method_status);
 	pidgin_blist_sort_method_reg("log_size", _("By recent log activity"), sort_method_log_activity);
 #endif
-	pidgin_blist_sort_method_set(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/sort_type"));
+
+	id = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/sort_type");
+	if (id == NULL) {
+		purple_debug_warning("gtkblist", "Sort method was NULL, resetting to alphabetical\n");
+		id = "alphabetical";
+	}
+	pidgin_blist_sort_method_set(id);
 }
 
 static void _prefs_change_redo_list(const char *name, PurplePrefType type,
@@ -7432,7 +7440,13 @@ void pidgin_blist_sort_method_reg(const 
 
 void pidgin_blist_sort_method_reg(const char *id, const char *name, pidgin_blist_sort_function func)
 {
-	struct pidgin_blist_sort_method *method = g_new0(struct pidgin_blist_sort_method, 1);
+	struct pidgin_blist_sort_method *method;
+
+	g_return_if_fail(id != NULL);
+	g_return_if_fail(name != NULL);
+	g_return_if_fail(func != NULL);
+
+	method = g_new0(struct pidgin_blist_sort_method, 1);
 	method->id = g_strdup(id);
 	method->name = g_strdup(name);
 	method->func = func;
@@ -7444,6 +7458,8 @@ void pidgin_blist_sort_method_unreg(cons
 {
 	GList *l = pidgin_blist_sort_methods;
 
+	g_return_if_fail(id != NULL);
+
 	while(l) {
 		struct pidgin_blist_sort_method *method = l->data;
 		if(!strcmp(method->id, id)) {
@@ -8033,6 +8049,8 @@ pidgin_blist_update_sort_methods(void)
 	if ((gtkblist == NULL) || (gtkblist->ift == NULL))
 		return;
 
+	g_return_if_fail(m != NULL);
+
 	sortmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Sort Buddies"));
 
 	if (sortmenu == NULL)
@@ -8047,7 +8065,7 @@ pidgin_blist_update_sort_methods(void)
 	for (l = pidgin_blist_sort_methods; l; l = l->next) {
 		method = (PidginBlistSortMethod *) l->data;
 		menuitem = gtk_radio_menu_item_new_with_label(sl, _(method->name));
-		if (!strcmp(m, method->id))
+		if (g_str_equal(m, method->id))
 			activeitem = menuitem;
 		sl = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem));
 		gtk_menu_shell_append(GTK_MENU_SHELL(sortmenu), menuitem);


More information about the Commits mailing list