X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_avltree.c;h=ecaf3c915967b2daee20489b9d8aa02aa41e6de6;hb=cf872835b60a3ec683b428832fbc79d6aa2df939;hp=f71b1fd6913bbc9676bb0e494d26bba1f829e7c2;hpb=51a4e62d7d0e73d8d5822efaef1e3218b5ad0373;p=collectd.git diff --git a/src/utils_avltree.c b/src/utils_avltree.c index f71b1fd6..ecaf3c91 100644 --- a/src/utils_avltree.c +++ b/src/utils_avltree.c @@ -142,6 +142,9 @@ static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x) c_avl_node_t *y; c_avl_node_t *b; + assert (x != NULL); + assert (x->left != NULL); + p = x->parent; y = x->left; b = y->right; @@ -166,7 +169,7 @@ static c_avl_node_t *rotate_right (c_avl_tree_t *t, c_avl_node_t *x) y->height = calc_height (y); return (y); -} /* void rotate_left */ +} /* void rotate_right */ /* * (x) (y) @@ -183,6 +186,9 @@ static c_avl_node_t *rotate_left (c_avl_tree_t *t, c_avl_node_t *x) c_avl_node_t *y; c_avl_node_t *b; + assert (x != NULL); + assert (x->right != NULL); + p = x->parent; y = x->right; b = y->left; @@ -613,10 +619,18 @@ int c_avl_pick (c_avl_tree_t *t, void **key, void **value) n = t->root; while ((n->left != NULL) || (n->right != NULL)) { - int height_left = (n->left == NULL) ? 0 : n->left->height; - int height_right = (n->right == NULL) ? 0 : n->right->height; + if (n->left == NULL) + { + n = n->right; + continue; + } + else if (n->right == NULL) + { + n = n->left; + continue; + } - if (height_left > height_right) + if (n->left->height > n->right->height) n = n->left; else n = n->right;