From 6ec600d29b5c4efeecfddd1cf35209b7ed527869 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 1 Apr 2023 00:53:01 -0400 Subject: [PATCH] kernel/util: Add self-link assertions to list_add_link_to_{head|tail}. These caught the problem fixed in prior commits, and would have saved me an awful lot of debugging time had they existed from the start. They cannot catch all double-list-insertions, of course, but it's relatively cheap to add these, and more than nothing. --- src/system/kernel/util/list.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/system/kernel/util/list.cpp b/src/system/kernel/util/list.cpp index 719772a95b..266e552aa2 100644 --- a/src/system/kernel/util/list.cpp +++ b/src/system/kernel/util/list.cpp @@ -49,6 +49,10 @@ list_add_link_to_head(struct list *list, void *_link) list->link.next->prev = link; list->link.next = link; + +#if DEBUG_DOUBLY_LINKED_LIST + ASSERT(link->next != link); +#endif } @@ -65,6 +69,10 @@ list_add_link_to_tail(struct list *list, void *_link) list->link.prev->next = link; list->link.prev = link; + +#if DEBUG_DOUBLY_LINKED_LIST + ASSERT(link->prev != link); +#endif }