[PATCH libinput 1/3] util: add asserts with useful error messages to catch uninitialized lists
Peter Hutterer
peter.hutterer at who-t.net
Fri May 5 08:22:01 UTC 2017
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/libinput-util.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/libinput-util.c b/src/libinput-util.c
index 38594fa4..eeeeca07 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;
}
--
2.12.2
More information about the wayland-devel
mailing list