fix cx_linked_list_sort() not working for empty lists

Fri, 05 May 2023 19:07:56 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 05 May 2023 19:07:56 +0200
changeset 702
3390b58ad15a
parent 701
72a440c437e9
child 703
425d4279856f

fix cx_linked_list_sort() not working for empty lists

src/linked_list.c file | annotate | diff | comparison | revisions
tests/test_list.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/linked_list.c	Mon Apr 24 19:08:56 2023 +0200
     1.2 +++ b/src/linked_list.c	Fri May 05 19:07:56 2023 +0200
     1.3 @@ -355,6 +355,9 @@
     1.4      // set start node
     1.5      ls = *begin;
     1.6  
     1.7 +    // early exit when this list is empty
     1.8 +    if (ls == NULL) return;
     1.9 +
    1.10      // check how many elements are already sorted
    1.11      lc = ls;
    1.12      size_t ln = 1;
     2.1 --- a/tests/test_list.cpp	Mon Apr 24 19:08:56 2023 +0200
     2.2 +++ b/tests/test_list.cpp	Fri May 05 19:07:56 2023 +0200
     2.3 @@ -509,6 +509,13 @@
     2.4      }
     2.5  }
     2.6  
     2.7 +TEST(LinkedList_LowLevel, cx_linked_list_sort_empty) {
     2.8 +    void *begin = nullptr;
     2.9 +    EXPECT_NO_FATAL_FAILURE(
    2.10 +        cx_linked_list_sort(&begin, nullptr, loc_prev, loc_next, loc_data, cx_cmp_int);
    2.11 +    );
    2.12 +}
    2.13 +
    2.14  TEST(LinkedList_LowLevel, cx_linked_list_sort) {
    2.15      int_test_data<1500> testdata;
    2.16      std::array<int, 1500> sorted{};

mercurial