From dcdf32e2e4d3b4d996646b61c994bd5b63fe5b96 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 10 Jun 2022 16:29:54 +0300 Subject: [PATCH 1/2] Fix list sort bug --- src/list/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/list/sort.c b/src/list/sort.c index 037881f..8b927b4 100644 --- a/src/list/sort.c +++ b/src/list/sort.c @@ -34,7 +34,7 @@ void list_sort(list_t* x) { lnode_t *p = l->prev; for (lnode_t* c = l; c != r; c = c->next) { - if (lnode_compare(c, r) < 0) { + if (lnode_compare(c, r) <= 0) { p = (is_null(p)) ? l : p->next; lnode_swap(p, c); } From 333e9fd675294c3fd5ca683099dc24f096df0135 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Fri, 10 Jun 2022 17:59:53 +0300 Subject: [PATCH 2/2] Fix list slice --- src/list/copy.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/list/copy.c b/src/list/copy.c index c9839c6..b790652 100644 --- a/src/list/copy.c +++ b/src/list/copy.c @@ -169,17 +169,14 @@ size_t list_slice(list_t* x, list_t* s, ssize_t i, size_t n, _Bool cut) { } else { if (c->prev) { c->prev->next = e->next; - } else x->first = e->next; + } else s->first = e->next; if (e->next) { e->next->prev = c->prev; } else s->last = c->prev; - e->next = nullptr; - c->prev = nullptr; - - x->first = c; - x->last = e; + (x->first = c)->prev = nullptr; + (x->last = e)->next = nullptr; } return r;