summaryrefslogtreecommitdiff
path: root/lib/linklist.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2022-10-24 14:08:35 -0400
committerDonald Sharp <sharpd@nvidia.com>2022-11-04 13:29:36 -0400
commite483855d24a0568c8e4c696f83fd9d999313589a (patch)
treef2ae02cd32509e40cc9a43ef060611e60cb46a80 /lib/linklist.c
parent3e85fb337332c8dbdf0a8834515170556f530b94 (diff)
lib: When adding to front of list ensure we handle tail to
When inserting to the front of a list with listnode_add_head if the list is empty, the tail will not be properly set and subsuquent calls to insert/remove will cause the function to crash. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'lib/linklist.c')
-rw-r--r--lib/linklist.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/linklist.c b/lib/linklist.c
index 8519482885..d1b57084ef 100644
--- a/lib/linklist.c
+++ b/lib/linklist.c
@@ -98,9 +98,10 @@ void listnode_add_head(struct list *list, void *val)
node->next = list->head;
- if (list->head == NULL)
+ if (list->head == NULL) {
list->head = node;
- else
+ list->tail = node;
+ } else
list->head->prev = node;
list->head = node;