From f4c7c387dcb6e3dfe84460cf7a60637019f69a64 Mon Sep 17 00:00:00 2001 From: Michel van den Hoek Date: Mon, 8 May 2023 14:01:17 +0200 Subject: [PATCH] issue 1682: fibheap.c: add assert to detect decrease_key on node outside of heap Signed-off-by: Michel van den Hoek --- src/ddsrt/src/fibheap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ddsrt/src/fibheap.c b/src/ddsrt/src/fibheap.c index 6313f6747e..529ebb10da 100644 --- a/src/ddsrt/src/fibheap.c +++ b/src/ddsrt/src/fibheap.c @@ -282,6 +282,8 @@ void ddsrt_fibheap_decrease_key (const ddsrt_fibheap_def_t *fhdef, ddsrt_fibheap caller is concerned => declare as const argument, then drop the const qualifier */ ddsrt_fibheap_node_t *node = (ddsrt_fibheap_node_t *) ((char *) vnode + fhdef->offset); + /* Sanity check that the node is actually part of the heap */ + assert(node->next != node ? node->next->prev == node : (node->parent == NULL ? fh->roots == node : node->parent->children == node)); if (node->parent && cmp (fhdef, node->parent, node) <= 0) { /* heap property not violated, do nothing */