Sun, 26 Sep 2021 15:26:43 +0200
fix special cases for linked_list_add
src/linked_list.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/linked_list.c Sun Sep 26 14:45:51 2021 +0200 1.2 +++ b/src/linked_list.c Sun Sep 26 15:26:43 2021 +0200 1.3 @@ -55,18 +55,24 @@ 1.4 void *last = cx_linked_list_last(begin, end, loc_next); 1.5 if (last == NULL) { 1.6 if (begin == NULL) { 1.7 + // no current list and no begin ptr to write to - we don't find something to append to 1.8 return 1; 1.9 } else { 1.10 + // start fresh list 1.11 *begin = new_node; 1.12 - return 0; 1.13 } 1.14 + } else { 1.15 + // if there is a last node, update its next pointer 1.16 + void **next = CX_LL_PTR(last, loc_next); 1.17 + *next = new_node; 1.18 } 1.19 1.20 - void **next = CX_LL_PTR(last, loc_next); 1.21 - *next = new_node; 1.22 + // if there is an end pointer, update it 1.23 if (end != NULL) { 1.24 *end = cx_linked_list_last(&new_node, NULL, loc_next); 1.25 } 1.26 + 1.27 + // if the nodes use a prev pointer, update it 1.28 if (loc_prev >= 0) { 1.29 void **prev = CX_LL_PTR(new_node, loc_prev); 1.30 *prev = last;