Fix an issue scanbuild found by making the function readable release-2.x.y

Tue, 01 Jun 2021 17:36:33 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 01 Jun 2021 17:36:33 -0500
branch
release-2.x.y
changeset 40904
b6f7ee1f368a
parent 40903
5c79001c7e86
child 40905
f2cec5958ed7

Fix an issue scanbuild found by making the function readable

Testing Done:
Ran scanbuild and verified the error was fixed.

Reviewed at https://reviews.imfreedom.org/r/696/

libpurple/notify.c file | annotate | diff | comparison | revisions
--- a/libpurple/notify.c	Tue Jun 01 17:36:18 2021 -0500
+++ b/libpurple/notify.c	Tue Jun 01 17:36:33 2021 -0500
@@ -746,17 +746,21 @@
 void
 purple_notify_close_with_handle(void *handle)
 {
-	GList *l, *prev = NULL;
+	GList *l;
 	PurpleNotifyUiOps *ops;
 
 	g_return_if_fail(handle != NULL);
 
 	ops = purple_notify_get_ui_ops();
 
-	for (l = handles; l != NULL; l = prev ? prev->next : handles) {
-		PurpleNotifyInfo *info = l->data;
+	l = handles;
+	while(l != NULL) {
+		PurpleNotifyInfo *info = (PurpleNotifyInfo *)l->data;
 
-		if (info->handle == handle) {
+		if(info != NULL && info->handle == handle) {
+			/* Move to the next item before we remove our current item. */
+			l = l->next;
+
 			handles = g_list_remove(handles, info);
 
 			if (ops != NULL && ops->close_notify != NULL)
@@ -766,8 +770,9 @@
 				info->cb(info->cb_user_data);
 
 			g_free(info);
-		} else
-			prev = l;
+		} else {
+			l = l->next;
+		}
 	}
 }
 

mercurial