util: add an extra assert for list_insert()
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 18 Oct 2017 05:24:03 +0000 (15:24 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 18 Oct 2017 06:17:22 +0000 (16:17 +1000)
If we're adding an element that's not null or not a freshly initialized list,
chances are we haven't removed it from a previous list.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
src/libinput-util.c

index 48cb71811ada62918653814a0ce6354832b34c80..93d73827bd15bbfc67a4c948697850417359378f 100644 (file)
@@ -52,6 +52,8 @@ list_insert(struct list *list, struct list *elm)
 {
        assert((list->next != NULL && list->prev != NULL) ||
               !"list->next|prev is NULL, possibly missing list_init()");
+       assert(((elm->next == NULL && elm->prev == NULL) || list_empty(elm)) ||
+              !"elm->next|prev is not NULL, list node used twice?");
 
        elm->prev = list;
        elm->next = list->next;