Skip to content

Commit

Permalink
util: add asserts with useful error messages to catch uninitialized l…
Browse files Browse the repository at this point in the history
…ists

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed May 4, 2017
1 parent 96fa426 commit 87b04a0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libinput-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 87b04a0

Please sign in to comment.