--- a/src/cx/list.h Wed Oct 08 20:20:54 2025 +0200 +++ b/src/cx/list.h Fri Oct 10 12:26:43 2025 +0200 @@ -39,6 +39,8 @@ #include "common.h" #include "collection.h" +#include <assert.h> + #ifdef __cplusplus extern "C" { #endif @@ -481,7 +483,8 @@ CxList *list, const void *elem ) { - list->collection.sorted = true; // guaranteed by definition + assert(list->collection.sorted || list->collection.size == 0); + list->collection.sorted = true; const void *data = list->collection.store_pointer ? &elem : elem; return list->cl->insert_sorted(list, data, 1) == 0; } @@ -541,7 +544,8 @@ const void *array, size_t n ) { - list->collection.sorted = true; // guaranteed by definition + assert(list->collection.sorted || list->collection.size == 0); + list->collection.sorted = true; return list->cl->insert_sorted(list, array, n); } @@ -779,8 +783,8 @@ */ cx_attr_nonnull static inline void cxListClear(CxList *list) { + list->cl->clear(list); list->collection.sorted = true; // empty lists are always sorted - list->cl->clear(list); } /**