summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Cardell Widerkrantz <mc@hack.org>2011-02-24 07:23:02 +0100
committerMichael Cardell Widerkrantz <mc@hack.org>2011-03-08 12:14:38 +0100
commit0acf6c27267b63f9e11f0374346e53c423addd14 (patch)
tree6277951602d0a7db947396c87e39d6ef34cec297
parentb61c62214ef5fb2d0b1bc5604b74e7dbcd778071 (diff)
downloadmcwm-0acf6c27267b63f9e11f0374346e53c423addd14.zip
Bug in movetohead(). Old head needs to be updated with new prev
pointer.
-rw-r--r--list.c9
1 files 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;
}