From 0acf6c27267b63f9e11f0374346e53c423addd14 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Thu, 24 Feb 2011 07:23:02 +0100 Subject: Bug in movetohead(). Old head needs to be updated with new prev pointer. --- list.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/list.c b/list.c index 995d091..d6ecb1a 100644 --- a/list.c +++ b/list.c @@ -23,7 +23,7 @@ void movetohead(struct item **mainlist, struct item *item) if (*mainlist == item) { - /* Already at head. Do nothing. */ + /* item is NULL or we're already at head. Do nothing. */ return; } @@ -38,10 +38,15 @@ void movetohead(struct item **mainlist, struct item *item) item->next->prev = item->prev; } - /* Now at head. */ + /* Now we'at head, so no one before us. */ item->prev = NULL; + + /* Old head is our next. */ item->next = *mainlist; + /* Old head needs to know about us. */ + item->next->prev = item; + /* Remember the new head. */ *mainlist = item; } -- cgit v1.2.3