aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-03-13 16:02:08 +0100
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2023-03-13 16:02:08 +0100
commit047c76825c9eea6b3475123e5627ee470c515934 (patch)
tree3a624ac163476ceb31748ea7024fca65c841af5d
parent92672025903b9ffdc9b9199f87ff669ae2ca8f86 (diff)
downloadutils-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.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/list.c b/src/list.c
index 542055d..3aa54bb 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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,