diff options
author | Dan McGee <dan@archlinux.org> | 2007-11-11 17:47:28 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-11-11 17:47:28 +0100 |
commit | 4a835f5f53f23d3564ceb4f53b84f4b62b0074fe (patch) | |
tree | 399018b5566a4dc750c795eb5c5df149e7e721fc /lib | |
parent | b6b3b0135edd7bf0fae43bfe522e41cfa5eb0d9b (diff) | |
download | pacman-4a835f5f53f23d3564ceb4f53b84f4b62b0074fe.tar.gz pacman-4a835f5f53f23d3564ceb4f53b84f4b62b0074fe.tar.xz |
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 <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm_list.c | 12 |
1 files changed, 10 insertions, 2 deletions
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; } |