]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use NIL for root
authorAlan T. DeKok <aland@freeradius.org>
Mon, 15 Feb 2021 22:15:35 +0000 (17:15 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 15 Feb 2021 22:15:35 +0000 (17:15 -0500)
and make NIL point to itself as it's parent

src/lib/rbtree.c
src/tests/rbmonkey.c

index c1e9fc6315bf1a9c6edf9b88eda58405e02e153b..d9892bdeb7c8145357db0324b2ac8d4934af2f2c 100644 (file)
@@ -49,9 +49,9 @@ struct rbnode_t {
 };
 
 #define NIL &sentinel     /* all leafs are sentinels */
-static rbnode_t sentinel = { NIL, NIL, NULL, BLACK, NULL};
+static rbnode_t sentinel = { NIL, NIL, NIL, BLACK, NULL};
 
-#define NOT_AT_ROOT(_node) ((_node) != NULL)
+#define NOT_AT_ROOT(_node) ((_node) != NIL)
 
 struct rbtree_t {
 #ifndef NDEBUG
@@ -265,7 +265,7 @@ rbnode_t *rbtree_insert_node(rbtree_t *tree, void *data)
 
        /* find where node belongs */
        current = tree->root;
-       parent = NULL;
+       parent = NIL;
        while (current != NIL) {
                int result;
 
index e5e17694387307e99973f61b0165c23034efe50c..dd58ff0fbd41f6bf77e454a3b82b4933ee011ef9 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <netdb.h>
+#include <assert.h>
 
 #include <freeradius-devel/libradius.h>
 
@@ -136,7 +137,7 @@ descend:
                }
        }
 ascend:
-       if (!n->parent) return count_expect;
+       if (n->parent != NIL) return count_expect;
        while (n->parent->right == n) {
                n = n->parent;
                if (!n->parent) return count_expect;
@@ -186,7 +187,9 @@ again:
 
        t = rbtree_create(NULL, comp, free, RBTREE_FLAG_LOCK);
        /* Find out the value of the NIL node */
-       NIL = t->root->left;
+       assert(t->root != NULL);
+       assert(t->root->parent == t->root);
+       NIL = t->root;
 
        for (i = 0; i < n; i++) {
                int *p;