util: add asserts with useful error messages to catch uninitialized lists

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2017-05-04 14:52:09 +10:00
parent 96fa4266d0
commit 87b04a0cb2

View file

@ -50,6 +50,9 @@ list_init(struct list *list)
void
list_insert(struct list *list, struct list *elm)
{
assert((list->next != NULL && list->prev != NULL) ||
!"list->next|prev is NULL, possibly missing list_init()");
elm->prev = list;
elm->next = list->next;
list->next = elm;
@ -59,6 +62,9 @@ list_insert(struct list *list, struct list *elm)
void
list_remove(struct list *elm)
{
assert((elm->next != NULL && elm->prev != NULL) ||
!"list->next|prev is NULL, possibly missing list_init()");
elm->prev->next = elm->next;
elm->next->prev = elm->prev;
elm->next = NULL;
@ -68,6 +74,9 @@ list_remove(struct list *elm)
bool
list_empty(const struct list *list)
{
assert((list->next != NULL && list->prev != NULL) ||
!"list->next|prev is NULL, possibly missing list_init()");
return list->next == list;
}