From 376cd3b89c62f580a6f576cecfbbb28d3944118f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 6 May 2014 13:07:15 +0200 Subject: list: make LIST_FIND_TAIL work for empty lists --- src/shared/list.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/shared/list.h') diff --git a/src/shared/list.h b/src/shared/list.h index e55b91cea4..c020f7e936 100644 --- a/src/shared/list.h +++ b/src/shared/list.h @@ -75,20 +75,26 @@ #define LIST_FIND_HEAD(name,item,head) \ do { \ typeof(*(item)) *_item = (item); \ - assert(_item); \ - while (_item->name##_prev) \ - _item = _item->name##_prev; \ - (head) = _item; \ + if (!_item) \ + (head) = NULL; \ + else { \ + while (_item->name##_prev) \ + _item = _item->name##_prev; \ + (head) = _item; \ + } \ } while (false) /* Find the tail of the list */ #define LIST_FIND_TAIL(name,item,tail) \ do { \ typeof(*(item)) *_item = (item); \ - assert(_item); \ - while (_item->name##_next) \ - _item = _item->name##_next; \ - (tail) = _item; \ + if (!_item) \ + (tail) = NULL; \ + else { \ + while (_item->name##_next) \ + _item = _item->name##_next; \ + (tail) = _item; \ + } \ } while (false) /* Insert an item after another one (a = where, b = what) */ -- cgit v1.2.3-54-g00ecf