From c4548c4355d4bb3f59418bdb00488222c88a3b94 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 30 May 2018 20:21:27 +0200 Subject: [PATCH] Fix splice_at which was broken. --- m-i-list.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/m-i-list.h b/m-i-list.h index d82d52ad..adb931b7 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -470,17 +470,25 @@ typedef struct ilist_head_s { ILISTI_CONTRACT(name, nlist); \ ILISTI_CONTRACT(name, olist); \ assert (npos != NULL && opos != NULL); \ + assert (!M_C(name, _end_p)(opos)); \ + /* npos may be end */ \ (void) olist, (void) nlist; \ type *obj = M_C(name, _ref)(opos); \ - type *refObj = M_C(name, _ref)(npos); \ - /* Set npos iterator to new position of object */ \ - npos->previous = &refObj->name; \ - npos->current = &obj->name; \ - npos->next = refObj->name.next; \ + struct ilist_head_s *ref = npos->current; \ + /* Remove object */ \ + M_C(name, _unlink)(obj); \ + /* Push 'obj' after 'ref' */ \ + struct ilist_head_s *next = ref->next; \ + ref->next = &obj->name; \ + obj->name.next = next; \ + obj->name.prev = ref; \ + next->prev = &obj->name; \ /* Move iterator in old list */ \ M_C(name, _next)(opos); \ - M_C(name, _unlink)(obj); \ - M_C(name, _push_after)(refObj, obj); \ + /* Set npos iterator to new position of object */ \ + npos->previous = ref; \ + npos->current = &obj->name; \ + npos->next = next; \ ILISTI_CONTRACT(name, nlist); \ ILISTI_CONTRACT(name, olist); \ } \