summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2017-05-04 14:52:09 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2017-05-04 15:28:58 +1000
commit87b04a0cb222c6b255f247c7b76d1b6424733964 (patch)
tree27bac3bd88f2a4f959d00d2fa16a8e706441ac34
parent96fa4266d0a660df4d3daffbc148801b7982143d (diff)
util: add asserts with useful error messages to catch uninitialized lists
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/libinput-util.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libinput-util.c b/src/libinput-util.c
index 38594fa..eeeeca0 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -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;
}