summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libcnary/node_list.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libcnary/node_list.c b/libcnary/node_list.c
index 2a9cf90..78f450e 100644
--- a/libcnary/node_list.c
+++ b/libcnary/node_list.c
@@ -59,7 +59,10 @@ int node_list_add(node_list_t* list, node_t* node) {
59 node->prev = last; 59 node->prev = last;
60 60
61 // Set the next element of our old "last" element 61 // Set the next element of our old "last" element
62 last->next = node; 62 if (last) {
63 // but only if the node list is not empty
64 last->next = node;
65 }
63 66
64 // Set the lists prev to the new last element 67 // Set the lists prev to the new last element
65 list->end = node; 68 list->end = node;
@@ -129,6 +132,9 @@ int node_list_remove(node_list_t* list, node_t* node) {
129 node->prev->next = newnode; 132 node->prev->next = newnode;
130 if (newnode) { 133 if (newnode) {
131 newnode->prev = node->prev; 134 newnode->prev = node->prev;
135 } else {
136 // last element in the list
137 list->end = node->prev;
132 } 138 }
133 } else { 139 } else {
134 // we just removed the first element 140 // we just removed the first element