diff options
author | 2023-03-13 16:02:08 +0100 | |
---|---|---|
committer | 2023-03-13 16:02:08 +0100 | |
commit | 047c76825c9eea6b3475123e5627ee470c515934 (patch) | |
tree | 3a624ac163476ceb31748ea7024fca65c841af5d | |
parent | 92672025903b9ffdc9b9199f87ff669ae2ca8f86 (diff) | |
download | utils-047c76825c9eea6b3475123e5627ee470c515934.tar.gz utils-047c76825c9eea6b3475123e5627ee470c515934.zip |
Change the logic to add_all collection
We call clist_add inside the loop instead to play with pointers 'cause
the data will be copied instead of referenced. So if the programmer
clear the second list, the data will be stay there.
-rw-r--r-- | src/list.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -58,8 +58,13 @@ clist_add(list_t *list, void clist_add_all(list_t *dest, list_t *other) { - dest->last->next = other->first; - dest->size += other->size; + /* Concatenation of both lists must be iterated and not referenced becasue + * if you clear `other` you'll lost all elements */ + + iterator_t i = clist_iterator(other); + while (clist_iterator_has_next(i)) { + clist_add(dest, clist_iterator_next(&i)); + } } void clist_remove(list_t *list, |