libubox: tests: add more blobmsg/json test cases
[project/libubox.git] / avl.c
diff --git a/avl.c b/avl.c
index f17dab5e354b0c4566ff69022a02cdb2ce20f56e..79ea5c798b64dbde78e7a7e445ba84cfc6b7ec33 100644 (file)
--- a/avl.c
+++ b/avl.c
@@ -45,6 +45,7 @@
 #include <string.h>
 
 #include "avl.h"
+#include "assert.h"
 #include "list.h"
 
 /**
@@ -98,6 +99,11 @@ avl_init(struct avl_tree *tree, avl_tree_comp comp, bool allow_dups, void *ptr)
   tree->cmp_ptr = ptr;
 }
 
+static inline struct avl_node *avl_next(struct avl_node *node)
+{
+    return list_entry(node->list.next, struct avl_node, list);
+}
+
 /**
  * Finds a node in an avl-tree with a certain key
  * @param tree pointer to avl-tree
@@ -236,7 +242,7 @@ avl_insert(struct avl_tree *tree, struct avl_node *new)
   last = node;
 
   while (!list_is_last(&last->list, &tree->list_head)) {
-    next = list_next_element(last, list);
+    next = avl_next(last);
     if (next->leader) {
       break;
     }
@@ -307,7 +313,7 @@ avl_delete(struct avl_tree *tree, struct avl_node *node)
   if (node->leader) {
     if (tree->allow_dups
         && !list_is_last(&node->list, &tree->list_head)
-        && !(next = list_next_element(node, list))->leader) {
+        && !(next = avl_next(node))->leader) {
       next->leader = true;
       next->balance = node->balance;
 
@@ -498,7 +504,7 @@ avl_insert_after(struct avl_tree *tree, struct avl_node *pos_node, struct avl_no
 static void
 avl_remove(struct avl_tree *tree, struct avl_node *node)
 {
-  list_remove(&node->list);
+  list_del(&node->list);
   tree->count--;
 }
 
@@ -663,6 +669,7 @@ avl_delete_worker(struct avl_tree *tree, struct avl_node *node)
       return;
     }
 
+    assert(node->right);
     node->right->parent = parent;
 
     if (parent->left == node)