[pacman-dev] Problems with alpm_list_remove(_node)

Dan McGee dpmcgee at gmail.com
Fri Nov 9 16:20:54 EST 2007


On Nov 9, 2007 2:55 PM, Xavier <shiningxc at gmail.com> wrote:
> On Fri, Nov 09, 2007 at 08:54:52PM +0100, Nagy Gabor wrote:
> > Some more issues:
> > 1. You simply forgot about resetting the tail pointer when you remove
> > the last element with alpm_list_remove.
>
> Yep, that's what explains the requiredby problem I noticed :
> http://www.archlinux.org/pipermail/pacman-dev/2007-November/009919.html
> Good catch :)

This should fix it.

diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 6f6ee8f..f2e57c0 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -311,6 +311,9 @@ alpm_list_t SYMEXPORT *alpm_list_remove(alpm_list_t *haystac
k, const void *needl
                                /* Normal case, non-head node */
                                if(i->next) {
                                        i->next->prev = i->prev;
+                               } else {
+                                       /* We are on the tail node, need to upda
te the back ref */
+                                       haystack->prev = i->prev;
                                }
                                if(i->prev) {
                                        i->prev->next = i->next;


> > 2. As I see, alpm_list_remove_node is used nowhere in the code, and
> > dangerous (when you remove the first or last node, "interesting" things
> > can happen); so that should be removed.
>
> Oh right, I first thought the requiredby problem was caused by the issues you
> mentioned in remove_node (I thought remove used remove_node), but indeed,
> this function isn't used anywhere.

Killed locally too. I'll probably commit this, although I want to
check where it was used originally before I kill it off.

-Dan




More information about the pacman-dev mailing list