comparison pidgin/gtkblist.c @ 27721:bbce09a8e5a5

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.
author Paul Aurich <paul@darkrain42.org>
date Mon, 20 Jul 2009 18:44:07 +0000
parents 5d75276a575f
children e1cd44c7c7af 429fce11f244
comparison
equal deleted inserted replaced
27720:6e952b8b3672 27721:bbce09a8e5a5
4640 return _((char *)path); 4640 return _((char *)path);
4641 } 4641 }
4642 4642
4643 void pidgin_blist_setup_sort_methods() 4643 void pidgin_blist_setup_sort_methods()
4644 { 4644 {
4645 const char *id;
4646
4645 pidgin_blist_sort_method_reg("none", _("Manually"), sort_method_none); 4647 pidgin_blist_sort_method_reg("none", _("Manually"), sort_method_none);
4646 #if GTK_CHECK_VERSION(2,2,1) 4648 #if GTK_CHECK_VERSION(2,2,1)
4647 pidgin_blist_sort_method_reg("alphabetical", _("Alphabetically"), sort_method_alphabetical); 4649 pidgin_blist_sort_method_reg("alphabetical", _("Alphabetically"), sort_method_alphabetical);
4648 pidgin_blist_sort_method_reg("status", _("By status"), sort_method_status); 4650 pidgin_blist_sort_method_reg("status", _("By status"), sort_method_status);
4649 pidgin_blist_sort_method_reg("log_size", _("By recent log activity"), sort_method_log_activity); 4651 pidgin_blist_sort_method_reg("log_size", _("By recent log activity"), sort_method_log_activity);
4650 #endif 4652 #endif
4651 pidgin_blist_sort_method_set(purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/sort_type")); 4653
4654 id = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/sort_type");
4655 if (id == NULL) {
4656 purple_debug_warning("gtkblist", "Sort method was NULL, resetting to alphabetical\n");
4657 id = "alphabetical";
4658 }
4659 pidgin_blist_sort_method_set(id);
4652 } 4660 }
4653 4661
4654 static void _prefs_change_redo_list(const char *name, PurplePrefType type, 4662 static void _prefs_change_redo_list(const char *name, PurplePrefType type,
4655 gconstpointer val, gpointer data) 4663 gconstpointer val, gpointer data)
4656 { 4664 {
7430 return pidgin_blist_sort_methods; 7438 return pidgin_blist_sort_methods;
7431 } 7439 }
7432 7440
7433 void pidgin_blist_sort_method_reg(const char *id, const char *name, pidgin_blist_sort_function func) 7441 void pidgin_blist_sort_method_reg(const char *id, const char *name, pidgin_blist_sort_function func)
7434 { 7442 {
7435 struct pidgin_blist_sort_method *method = g_new0(struct pidgin_blist_sort_method, 1); 7443 struct pidgin_blist_sort_method *method;
7444
7445 g_return_if_fail(id != NULL);
7446 g_return_if_fail(name != NULL);
7447 g_return_if_fail(func != NULL);
7448
7449 method = g_new0(struct pidgin_blist_sort_method, 1);
7436 method->id = g_strdup(id); 7450 method->id = g_strdup(id);
7437 method->name = g_strdup(name); 7451 method->name = g_strdup(name);
7438 method->func = func; 7452 method->func = func;
7439 pidgin_blist_sort_methods = g_list_append(pidgin_blist_sort_methods, method); 7453 pidgin_blist_sort_methods = g_list_append(pidgin_blist_sort_methods, method);
7440 pidgin_blist_update_sort_methods(); 7454 pidgin_blist_update_sort_methods();
7441 } 7455 }
7442 7456
7443 void pidgin_blist_sort_method_unreg(const char *id) 7457 void pidgin_blist_sort_method_unreg(const char *id)
7444 { 7458 {
7445 GList *l = pidgin_blist_sort_methods; 7459 GList *l = pidgin_blist_sort_methods;
7460
7461 g_return_if_fail(id != NULL);
7446 7462
7447 while(l) { 7463 while(l) {
7448 struct pidgin_blist_sort_method *method = l->data; 7464 struct pidgin_blist_sort_method *method = l->data;
7449 if(!strcmp(method->id, id)) { 7465 if(!strcmp(method->id, id)) {
7450 pidgin_blist_sort_methods = g_list_delete_link(pidgin_blist_sort_methods, l); 7466 pidgin_blist_sort_methods = g_list_delete_link(pidgin_blist_sort_methods, l);
8031 const char *m = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/sort_type"); 8047 const char *m = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/sort_type");
8032 8048
8033 if ((gtkblist == NULL) || (gtkblist->ift == NULL)) 8049 if ((gtkblist == NULL) || (gtkblist->ift == NULL))
8034 return; 8050 return;
8035 8051
8052 g_return_if_fail(m != NULL);
8053
8036 sortmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Sort Buddies")); 8054 sortmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Sort Buddies"));
8037 8055
8038 if (sortmenu == NULL) 8056 if (sortmenu == NULL)
8039 return; 8057 return;
8040 8058
8045 } 8063 }
8046 8064
8047 for (l = pidgin_blist_sort_methods; l; l = l->next) { 8065 for (l = pidgin_blist_sort_methods; l; l = l->next) {
8048 method = (PidginBlistSortMethod *) l->data; 8066 method = (PidginBlistSortMethod *) l->data;
8049 menuitem = gtk_radio_menu_item_new_with_label(sl, _(method->name)); 8067 menuitem = gtk_radio_menu_item_new_with_label(sl, _(method->name));
8050 if (!strcmp(m, method->id)) 8068 if (g_str_equal(m, method->id))
8051 activeitem = menuitem; 8069 activeitem = menuitem;
8052 sl = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem)); 8070 sl = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuitem));
8053 gtk_menu_shell_append(GTK_MENU_SHELL(sortmenu), menuitem); 8071 gtk_menu_shell_append(GTK_MENU_SHELL(sortmenu), menuitem);
8054 g_signal_connect(G_OBJECT(menuitem), "toggled", 8072 g_signal_connect(G_OBJECT(menuitem), "toggled",
8055 G_CALLBACK(sortmethod_act), method->id); 8073 G_CALLBACK(sortmethod_act), method->id);