# HG changeset patch # User Mike Becker # Date 1683306476 -7200 # Node ID 3390b58ad15a49f5ac7877d750a6a0704f36059f # Parent 72a440c437e9150c94f82c3240073068e3f16331 fix cx_linked_list_sort() not working for empty lists diff -r 72a440c437e9 -r 3390b58ad15a src/linked_list.c --- a/src/linked_list.c Mon Apr 24 19:08:56 2023 +0200 +++ b/src/linked_list.c Fri May 05 19:07:56 2023 +0200 @@ -355,6 +355,9 @@ // set start node ls = *begin; + // early exit when this list is empty + if (ls == NULL) return; + // check how many elements are already sorted lc = ls; size_t ln = 1; diff -r 72a440c437e9 -r 3390b58ad15a tests/test_list.cpp --- a/tests/test_list.cpp Mon Apr 24 19:08:56 2023 +0200 +++ b/tests/test_list.cpp Fri May 05 19:07:56 2023 +0200 @@ -509,6 +509,13 @@ } } +TEST(LinkedList_LowLevel, cx_linked_list_sort_empty) { + void *begin = nullptr; + EXPECT_NO_FATAL_FAILURE( + cx_linked_list_sort(&begin, nullptr, loc_prev, loc_next, loc_data, cx_cmp_int); + ); +} + TEST(LinkedList_LowLevel, cx_linked_list_sort) { int_test_data<1500> testdata; std::array sorted{};