diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-05-24 11:54:33 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-05-24 11:54:33 -0400 |
commit | eef75524aec3910097cb6923c30b898ad98179fe (patch) | |
tree | 9ceffbd76a5d63bb927ecb32990c6ce0adda9bbd /src/list.h | |
parent | bc952b51f48905392cec5685853fbb44565057a8 (diff) | |
download | bfs-eef75524aec3910097cb6923c30b898ad98179fe.tar.xz |
list: Allow popping from an empty list
Diffstat (limited to 'src/list.h')
-rw-r--r-- | src/list.h | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -280,11 +280,13 @@ static inline void *slist_remove_impl(void *ret, void *cursor, void *next, void * The list to pop from. * @param node (optional) * If specified, use head->node.next rather than head->next. + * @return + * The popped item, or NULL if the list was empty. */ #define SLIST_POP(...) SLIST_POP_(__VA_ARGS__, ) #define SLIST_POP_(list, ...) \ - SLIST_REMOVE_(list, &(list)->head, __VA_ARGS__) + ((list)->head ? SLIST_REMOVE_(list, &(list)->head, __VA_ARGS__) : NULL) /** * Initialize a doubly-linked list. |