X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Flist.h;h=c020f7e9369abe4eb89bb9d02d06722c0be5eecb;hb=376cd3b89c62f580a6f576cecfbbb28d3944118f;hp=e55b91cea4ad9c0184ee07390ba78a11c9c81a0a;hpb=2db3e2023d1af9eab6ebecddbf64812be2b104f5;p=elogind.git diff --git a/src/shared/list.h b/src/shared/list.h index e55b91cea..c020f7e93 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) */