summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMasoud Naservand <masoud.naservand@gmail.com>2022-02-17 15:39:05 +0330
committerPatrick <tingping@tingping.se>2022-02-17 10:24:59 -0600
commit94efa378f7f7329514b04a2f8dadf2b9d57b9f8e (patch)
tree0a81bb2a5296cef942549dff8c3eaba747e1a993
parentccf6f431bbd96f04369875d72a61976bb6609a69 (diff)
Reverse the notify.conf linked list before writing
hexchat populates the single linked list `notify_list` defined in
`src/common/notify.c` from `notify.conf` file. Each new line read from
the file is added to the list by `g_slist_prepend()` which adds it to
the front of the list. But in `notify_save()` the list elements are read
from the start to end of the list and written to the `notify.conf`. This
means everytime hexchat is opened and closed, the contents of
`notify.conf` get reversed. This commit creates a
temporary glist in `notify_save()` and applies `g_slist_reverse()` on it
and writes the contents of this reversed list to `notify.conf`. And
solves issue #2680
-rw-r--r--src/common/notify.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/common/notify.c b/src/common/notify.c
index b5316c36..ef52889b 100644
--- a/src/common/notify.c
+++ b/src/common/notify.c
@@ -123,7 +123,11 @@ notify_save (void)
 {
 	int fh;
 	struct notify *notify;
-	GSList *list = notify_list;
+        // while reading the notify.conf file, elements are added by prepending to the
+        // list. reverse the list before writing to disk to keep the original
+        // order of the list
+        GSList *list = g_slist_copy(notify_list);
+        list = g_slist_reverse(list);
 
 	fh = hexchat_open_file ("notify.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
 	if (fh != -1)
@@ -142,6 +146,7 @@ notify_save (void)
 		}
 		close (fh);
 	}
+        g_slist_free(list);
 }
 
 void