From 7dc743d21fe0cd74ee6a57c29235a57b2d17cb16 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 28 Dec 2021 16:17:50 -0600 Subject: [PATCH] Have llist_pop(0) return NULL the same way dlist_pop() does. --- lib/llist.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/llist.c b/lib/llist.c index e82cb954..6ceb1ce7 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -41,14 +41,13 @@ void llist_traverse(void *list, void (*using)(void *node)) // as &list) void *llist_pop(void *list) { - // I'd use a void ** for the argument, and even accept the typecast in all - // callers as documentation you need the &, except the stupid compiler - // would then scream about type-punned pointers. Screw it. - void **llist = (void **)list; - void **next = (void **)*llist; + void **llist = list, **next; + + if (!list || !*llist) return 0; + next = (void **)*llist; *llist = *next; - return (void *)next; + return next; } // Remove first item from &list and return it -- 2.39.2