diff -r ec92b4ed23aa -r da66264af8ad src/linked_list.c --- 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;