diff --git a/src/ChangeLog b/src/ChangeLog index 8646ac646..8c3b5e28d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2003-02-18 Pavel Roskin + * util.c (list_append_unique): Traverse the list backwards. + Otherwise the list was lost when the current link was removed. + * widget.c (history_get): Set the history to the last item. Reported by Adam Byrtek diff --git a/src/util.c b/src/util.c index ff9c5c3fb..489dcf1e2 100644 --- a/src/util.c +++ b/src/util.c @@ -1170,15 +1170,23 @@ list_append_unique (GList *list, char *text) { GList *link, *newlink; - link = g_list_first (list); + /* + * Go to the last position and traverse the list backwards + * starting from the second last entry to make sure that we + * are not removing the current link. + */ + list = g_list_append (list, text); + list = g_list_last (list); + link = g_list_previous (list); + while (link) { - newlink = g_list_next (link); + newlink = g_list_previous (link); if (!strcmp ((char *) link->data, text)) - list = g_list_remove_link (list, link); + g_list_remove_link (list, link); link = newlink; } - return g_list_append (list, text); + return list; }