diff -r 741a2040fa33 -r ccbdbd088455 src/array_list.c --- a/src/array_list.c Mon Dec 18 16:14:07 2023 +0100 +++ b/src/array_list.c Mon Dec 18 18:22:53 2023 +0100 @@ -363,9 +363,10 @@ } } -static ssize_t cx_arl_find( - struct cx_list_s const *list, - void const *elem +static ssize_t cx_arl_find_remove( + struct cx_list_s *list, + void const *elem, + bool remove ) { assert(list->cmpfunc != NULL); assert(list->size < SIZE_MAX / 2); @@ -373,7 +374,15 @@ for (ssize_t i = 0; i < (ssize_t) list->size; i++) { if (0 == list->cmpfunc(elem, cur)) { - return i; + if (remove) { + if (0 == cx_arl_remove(list, i)) { + return i; + } else { + return -1; + } + } else { + return i; + } } cur += list->item_size; } @@ -501,7 +510,7 @@ cx_arl_clear, cx_arl_swap, cx_arl_at, - cx_arl_find, + cx_arl_find_remove, cx_arl_sort, cx_arl_compare, cx_arl_reverse,