From a2eb39326c4dfa3e138a02cf16083bf296b35fa2 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 5 Apr 2021 01:46:31 +0200 Subject: Fixed another two bugs in clist.h. Think it's fine now. --- stc/clist.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stc/clist.h b/stc/clist.h index 4de4a4ab..2c6ada5a 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -230,22 +230,23 @@ STC_API size_t _clist_size(const clist_void* self); \ STC_DEF clist_##X##_iter_t \ clist_##X##_insert(clist_##X* self, clist_##X##_iter_t pos, Value value) { \ - clist_##X##_node_t* node = pos._prev ? pos._prev : self->last; \ + clist_##X##_node_t* node = pos.ref ? pos._prev : self->last; \ _c_clist_insert_after(self, X, node, value); \ - pos.ref = &entry->value; \ - if (!self->last || !pos._prev) { \ + if (!self->last || !pos.ref) { \ pos._prev = self->last ? self->last : entry; \ self->last = entry; \ } \ + pos.ref = &entry->value; \ return pos; \ } \ \ STC_DEF clist_##X##_iter_t \ clist_##X##_erase_at(clist_##X* self, clist_##X##_iter_t pos) { \ - clist_##X##_node_t* node = pos._prev; \ - if (pos.ref == self->last) pos.ref = pos._prev = NULL; \ - else pos.ref = &_clist_node(X, pos.ref)->next->value; \ - _clist_##X##_erase_after(self, node); return pos; \ + clist_##X##_node_t *node = _clist_node(X, pos.ref); \ + if (node == self->last) pos.ref = NULL; \ + else pos.ref = &node->next->value; \ + _clist_##X##_erase_after(self, pos._prev); \ + return pos; \ } \ STC_DEF clist_##X##_iter_t \ clist_##X##_erase_range(clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish) { \ -- cgit v1.2.3