From 90cc056dcd7ef04405c7e4d5535eb4ad2a349155 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 20 Jun 2019 16:59:49 -0500 Subject: Teach dlist_pop() to work on a dlist_terminate()d list --- lib/llist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/llist.c') diff --git a/lib/llist.c b/lib/llist.c index dbb5352a..2969102d 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -55,10 +55,12 @@ void *dlist_pop(void *list) { struct double_list **pdlist = (struct double_list **)list, *dlist = *pdlist; + if (!dlist) return 0; if (dlist->next == dlist) *pdlist = 0; else { - dlist->next->prev = dlist->prev; - dlist->prev->next = *pdlist = dlist->next; + if (dlist->next) dlist->next->prev = dlist->prev; + if (dlist->prev) dlist->prev->next = dlist->next; + *pdlist = dlist->next; } return dlist; -- cgit v1.2.3