fix special cases for linked_list_add

Sun, 26 Sep 2021 15:26:43 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 26 Sep 2021 15:26:43 +0200
changeset 428
da66264af8ad
parent 427
ec92b4ed23aa
child 429
3d8235c96a27
child 430
d4d643def2ac

fix special cases for linked_list_add

src/linked_list.c file | annotate | diff | comparison | revisions
--- a/src/linked_list.c	Sun Sep 26 14:45:51 2021 +0200
+++ b/src/linked_list.c	Sun Sep 26 15:26:43 2021 +0200
@@ -55,18 +55,24 @@
     void *last = cx_linked_list_last(begin, end, loc_next);
     if (last == NULL) {
         if (begin == NULL) {
+            // no current list and no begin ptr to write to - we don't find something to append to
             return 1;
         } else {
+            // start fresh list
             *begin = new_node;
-            return 0;
         }
+    } else {
+        // if there is a last node, update its next pointer
+        void **next = CX_LL_PTR(last, loc_next);
+        *next = new_node;
     }
 
-    void **next = CX_LL_PTR(last, loc_next);
-    *next = new_node;
+    // if there is an end pointer, update it
     if (end != NULL) {
         *end = cx_linked_list_last(&new_node, NULL, loc_next);
     }
+
+    // if the nodes use a prev pointer, update it
     if (loc_prev >= 0) {
         void **prev = CX_LL_PTR(new_node, loc_prev);
         *prev = last;

mercurial