From 589abda0c292b5bf563fac471ff0b2dcfbd6389b Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 13 Aug 2023 23:27:12 +0200 Subject: [PATCH] Fix bug in list insertion: The output iterator has its previous field incorrect. --- m-list.h | 1 + tests/test-mlist.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/m-list.h b/m-list.h index 9b7f8c63..7a79b9a9 100644 --- a/m-list.h +++ b/m-list.h @@ -503,6 +503,7 @@ } \ /* Update insertion_point to this element */ \ insertion_point->current = next; \ + insertion_point->previous = current; \ M_L1ST_CONTRACT(list); \ } \ \ diff --git a/tests/test-mlist.c b/tests/test-mlist.c index ff21caf7..0b40a20f 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -867,9 +867,36 @@ static void test_let_string(void) } } +static void test_insert_remove(void) +{ + list_uint_t l; + + list_uint_init(l); + list_uint_push_back(l, 1); + list_uint_push_back(l, 2); + list_uint_push_back(l, 3); + + list_uint_it_t u; + unsigned w= 4; + list_uint_it(u, l); + list_uint_next(u); + assert ( list_uint_size(l) == 3); + list_uint_insert(l, u, w); + assert ( list_uint_size(l) == 4); + list_uint_remove(l, u); + assert ( list_uint_size(l) == 3); + list_uint_insert(l, u, w); + assert ( list_uint_size(l) == 4); + list_uint_remove(l, u); + assert ( list_uint_size(l) == 3); + + list_uint_clear(l); +} + int main(void) { test_uint(); + test_insert_remove(); test_mpz(); test_dual_push1(); test_dual_it1();