--- a/src/list.c Sun Oct 26 12:44:33 2025 +0100 +++ b/src/list.c Sun Oct 26 12:50:43 2025 +0100 @@ -820,30 +820,20 @@ // now clone the elements size_t cloned = empl_iter.elem_count; - if (cxCollectionStoresPointers(dst)) { - for (size_t i = 0 ; i < empl_iter.elem_count; i++) { - void *src_elem = cxIteratorCurrent(src_iter); - void **dest_memory = cxIteratorCurrent(empl_iter); - void *dest_ptr = clone_func(NULL, src_elem, clone_allocator, data); - if (dest_ptr == NULL) { - cloned = i; - break; - } + for (size_t i = 0 ; i < empl_iter.elem_count; i++) { + void *src_elem = cxIteratorCurrent(src_iter); + void **dest_memory = cxIteratorCurrent(empl_iter); + void *target = cxCollectionStoresPointers(dst) ? NULL : dest_memory; + void *dest_ptr = clone_func(target, src_elem, clone_allocator, data); + if (dest_ptr == NULL) { + cloned = i; + break; + } + if (cxCollectionStoresPointers(dst)) { *dest_memory = dest_ptr; - cxIteratorNext(src_iter); - cxIteratorNext(empl_iter); } - } else { - for (size_t i = 0 ; i < empl_iter.elem_count; i++) { - void *src_elem = cxIteratorCurrent(src_iter); - void *dest_memory = cxIteratorCurrent(empl_iter); - if (clone_func(dest_memory, src_elem, clone_allocator, data) == NULL) { - cloned = i; - break; - } - cxIteratorNext(src_iter); - cxIteratorNext(empl_iter); - } + cxIteratorNext(src_iter); + cxIteratorNext(empl_iter); } // if we could not clone everything, free the allocated memory