From 4a835f5f53f23d3564ceb4f53b84f4b62b0074fe Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 11 Nov 2007 10:47:28 -0600 Subject: Ensure list tail pointer is updated when we remove tail node Commit 2ee90ddae23dd86c68223c0d6c49f0b92d62429d did a special check to see if we were removing the head node, but not the tail node. Add a special case for the tail node to ensure all relevant pointers get updated. Signed-off-by: Dan McGee --- lib/libalpm/alpm_list.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index d3a7951f..465c1a8f 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -301,14 +301,22 @@ alpm_list_t SYMEXPORT *alpm_list_remove(alpm_list_t *haystack, const void *needl if(i == haystack) { /* Special case: removing the head node which has a back reference to * the tail node */ - /* The item found is the first in the chain */ haystack = i->next; if(haystack) { haystack->prev = i->prev; } i->prev = NULL; + } else if(i == haystack->prev) { + /* Special case: removing the tail node, so we need to fix the back + * reference on the head node. We also know tail != head. */ + if(i->prev) { + /* i->next should always be null */ + i->prev->next = i->next; + haystack->prev = i->prev; + i->prev = NULL; + } } else { - /* Normal case, non-head node */ + /* Normal case, non-head and non-tail node */ if(i->next) { i->next->prev = i->prev; } -- cgit v1.2.3-70-g09d2