/soc/2012/michael/libpurple: b9046377fdde: Added a null test to ...

Michael Zangl michael at soc.pidgin.im
Thu May 9 05:53:19 EDT 2013


Changeset: b9046377fdde51718a5bcb1d0df2e341de26be2f
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2013-05-09 10:26 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2012/michael/libpurple/rev/b9046377fdde

Description:

Added a null test to all functions that access the blist root node.

diffstat:

 libpurple/blist.c |  20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diffs (86 lines):

diff --git a/libpurple/blist.c b/libpurple/blist.c
--- a/libpurple/blist.c
+++ b/libpurple/blist.c
@@ -763,7 +763,9 @@ purple_get_blist()
 PurpleBlistNode *
 purple_blist_get_root()
 {
-	return purplebuddylist ? purplebuddylist->root : NULL;
+	g_return_val_if_fail(purplebuddylist != NULL, NULL);
+	
+	return purplebuddylist->root;
 }
 
 static void
@@ -963,6 +965,8 @@ void purple_blist_rename_buddy(PurpleBud
 	GHashTable *account_buddies;
 
 	g_return_if_fail(buddy != NULL);
+	g_return_if_fail(((PurpleBlistNode *)buddy)->parent != NULL);
+	g_return_if_fail(((PurpleBlistNode *)buddy)->parent->parent != NULL);
 
 	hb = g_new(struct _purple_hbuddy, 1);
 	hb->name = (gchar *)purple_normalize(buddy->account, buddy->name);
@@ -1482,7 +1486,7 @@ void purple_blist_add_chat(PurpleChat *c
 		/* Add group to blist if isn't already on it. Fixes #2752. */
 		if (!purple_find_group(group->name)) {
 			purple_blist_add_group(group,
-					purple_blist_get_last_sibling(purplebuddylist->root));
+					purple_blist_get_last_sibling(purple_blist_get_root()));
 		}
 	} else {
 		group = (PurpleGroup*)node->parent;
@@ -1585,7 +1589,7 @@ void purple_blist_add_buddy(PurpleBuddy 
 		/* Add group to blist if isn't already on it. Fixes #2752. */
 		if (!purple_find_group(g->name)) {
 			purple_blist_add_group(g,
-					purple_blist_get_last_sibling(purplebuddylist->root));
+					purple_blist_get_last_sibling(purple_blist_get_root()));
 		}
 		c = purple_contact_new();
 		purple_blist_add_contact(c, g,
@@ -1835,7 +1839,7 @@ void purple_blist_add_contact(PurpleCont
 		if (g == NULL) {
 			g = purple_group_new(_("Buddies"));
 			purple_blist_add_group(g,
-					purple_blist_get_last_sibling(purplebuddylist->root));
+					purple_blist_get_last_sibling(purple_blist_get_root()));
 		}
 	}
 
@@ -2461,7 +2465,7 @@ GSList *purple_find_buddies(PurpleAccoun
 		hb.name = (gchar *)purple_normalize(account, name);
 		hb.account = account;
 
-		for (node = purplebuddylist->root; node != NULL; node = node->next) {
+		for (node = purple_blist_get_root(); node != NULL; node = node->next) {
 			if (!node->child)
 				continue;
 
@@ -2519,7 +2523,7 @@ purple_blist_find_chat(PurpleAccount *ac
 		return prpl_info->find_blist_chat(account, name);
 
 	normname = g_strdup(purple_normalize(account, name));
-	for (group = purplebuddylist->root; group != NULL; group = group->next) {
+	for (group = purple_blist_get_root(); group != NULL; group = group->next) {
 		for (node = group->child; node != NULL; node = node->next) {
 			if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
 
@@ -2643,7 +2647,7 @@ void purple_blist_add_account(PurpleAcco
 	if (!ops || !ops->update)
 		return;
 
-	for (gnode = purplebuddylist->root; gnode; gnode = gnode->next) {
+	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
 		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
 			continue;
 		for (cnode = gnode->child; cnode; cnode = cnode->next) {
@@ -2687,7 +2691,7 @@ void purple_blist_remove_account(PurpleA
 
 	g_return_if_fail(purplebuddylist != NULL);
 
-	for (gnode = purplebuddylist->root; gnode; gnode = gnode->next) {
+	for (gnode = purple_blist_get_root(); gnode; gnode = gnode->next) {
 		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
 			continue;
 



More information about the Commits mailing list