# HG changeset patch # User Stu Tomlinson # Date 1161878131 0 # Node ID 5e5b34ac509a185e2df257e8278ea8f9e3127bb3 # Parent 77c68f898389603e3843396c4ee7e7a783d9ca9a [gaim-migrate @ 17588] Don't rely on the sender or receiver of messages being a buddy, and add some other safeguards to prevent crashes like bug #1585017 I'm pretty sure this is good, but don't have the necessary sqlite installed to test this at the moment. committer: Tailor Script diff -r 77c68f898389 -r 5e5b34ac509a gtk/plugins/cap/cap.c --- a/gtk/plugins/cap/cap.c Thu Oct 26 06:20:18 2006 +0000 +++ b/gtk/plugins/cap/cap.c Thu Oct 26 15:55:31 2006 +0000 @@ -109,6 +109,9 @@ static CapStatistics * get_stats_for(GaimBuddy *buddy) { gchar *buddy_name; CapStatistics *stats; + + g_return_val_if_fail(buddy != NULL, NULL); + buddy_name = g_strdup(buddy->name); stats = g_hash_table_lookup(_buddy_stats, buddy_name); if(!stats) { @@ -340,9 +343,17 @@ /* sent-im-msg */ static void sent_im_msg(GaimAccount *account, const char *receiver, const char *message) { - GaimBuddy *buddy = gaim_find_buddy(account, receiver); - guint interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60; - guint words = word_count(message); + GaimBuddy *buddy; + guint interval, words; + + buddy = gaim_find_buddy(account, receiver); + + if (buddy == NULL) + return; + + interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60; + words = word_count(message); + CapStatistics *stats = get_stats_for(buddy); insert_word_count(gaim_account_get_username(account), receiver, words); @@ -357,9 +368,16 @@ /* received-im-msg */ static void received_im_msg(GaimAccount *account, char *sender, char *message, GaimConversation *conv, GaimMessageFlags flags) { - GaimBuddy *buddy = gaim_find_buddy(account, sender); + GaimBuddy *buddy; + CapStatistics *stats; /* guint words = word_count(message); */ - CapStatistics *stats = get_stats_for(buddy); + + buddy = gaim_find_buddy(account, sender); + + if (buddy == NULL) + return; + + stats = get_stats_for(buddy); /* insert_word_count(sender, buddy_name, words); */