--- a/src/list.c Wed Jan 21 22:47:18 2026 +0100 +++ b/src/list.c Sun Feb 08 14:22:13 2026 +0100 @@ -29,6 +29,7 @@ #include "cx/list.h" #include <string.h> +#include <errno.h> #include <assert.h> // we don't want to include the full array_list.h. @@ -418,6 +419,10 @@ int cxListAdd(CxList *list, const void *elem) { list->collection.sorted = false; + if (!cxCollectionStoresPointers(list) && elem == NULL) { + errno = EINVAL; + return 1; + } return list->cl->insert_element(list, list->collection.size, cx_ref(list, elem)) == NULL; } @@ -428,6 +433,10 @@ int cxListInsert(CxList *list, size_t index, const void *elem) { list->collection.sorted = false; + if (!cxCollectionStoresPointers(list) && elem == NULL) { + errno = EINVAL; + return 1; + } return list->cl->insert_element(list, index, cx_ref(list, elem)) == NULL; } @@ -465,12 +474,20 @@ int cxListInsertSorted(CxList *list, const void *elem) { assert(cxCollectionSorted(list)); list->collection.sorted = true; + if (!cxCollectionStoresPointers(list) && elem == NULL) { + errno = EINVAL; + return 1; + } return list->cl->insert_sorted(list, cx_ref(list, elem), 1) == 0; } int cxListInsertUnique(CxList *list, const void *elem) { if (cxCollectionSorted(list)) { list->collection.sorted = true; + if (!cxCollectionStoresPointers(list) && elem == NULL) { + errno = EINVAL; + return 1; + } return list->cl->insert_unique(list, cx_ref(list, elem), 1) == 0; } else { if (cxListContains(list, elem)) { @@ -515,12 +532,20 @@ int cxListInsertAfter(CxIterator *iter, const void *elem) { CxList* list = iter->src_handle; list->collection.sorted = false; + if (!cxCollectionStoresPointers(list) && elem == NULL) { + errno = EINVAL; + return 1; + } return list->cl->insert_iter(iter, cx_ref(list, elem), 0); } int cxListInsertBefore(CxIterator *iter, const void *elem) { CxList* list = iter->src_handle; list->collection.sorted = false; + if (!cxCollectionStoresPointers(list) && elem == NULL) { + errno = EINVAL; + return 1; + } return list->cl->insert_iter(iter, cx_ref(list, elem), 1); } @@ -626,10 +651,16 @@ } size_t cxListFind(const CxList *list, const void *elem) { + if (!cxCollectionStoresPointers(list) && elem == NULL) { + return list->collection.size; + } return list->cl->find_remove((CxList*)list, cx_ref(list, elem), false); } bool cxListContains(const CxList* list, const void* elem) { + if (!cxCollectionStoresPointers(list) && elem == NULL) { + return false; + } return list->cl->find_remove((CxList*)list, cx_ref(list, elem), false) < list->collection.size; } @@ -638,6 +669,9 @@ } size_t cxListFindRemove(CxList *list, const void *elem) { + if (!cxCollectionStoresPointers(list) && elem == NULL) { + return list->collection.size; + } return list->cl->find_remove(list, cx_ref(list, elem), true); }