X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_avltree.c;h=1680c41fe37fd8dd1fbc51312c47a9cff2aca4b7;hb=290741f2e6de9e9b467463c1f0c6f031c4036428;hp=e251975bac6479e8410d64aa9e16b898e38a8839;hpb=add25ce6f3129cb7138e96e5f55d11de1e5cf6de;p=collectd.git diff --git a/src/daemon/utils_avltree.c b/src/daemon/utils_avltree.c index e251975b..1680c41f 100644 --- a/src/daemon/utils_avltree.c +++ b/src/daemon/utils_avltree.c @@ -245,7 +245,7 @@ static void rebalance (c_avl_tree_t *t, c_avl_node_t *n) { assert (n->right != NULL); b_bottom = BALANCE (n->right); - assert ((b_bottom >= -1) || (b_bottom <= 1)); + assert ((b_bottom >= -1) && (b_bottom <= 1)); if (b_bottom == 1) n = rotate_right_left (t, n); else @@ -255,7 +255,7 @@ static void rebalance (c_avl_tree_t *t, c_avl_node_t *n) { assert (n->left != NULL); b_bottom = BALANCE (n->left); - assert ((b_bottom >= -1) || (b_bottom <= 1)); + assert ((b_bottom >= -1) && (b_bottom <= 1)); if (b_bottom == -1) n = rotate_left_right (t, n); else @@ -485,7 +485,7 @@ c_avl_tree_t *c_avl_create (int (*compare) (const void *, const void *)) if (compare == NULL) return (NULL); - if ((t = (c_avl_tree_t *) malloc (sizeof (c_avl_tree_t))) == NULL) + if ((t = malloc (sizeof (*t))) == NULL) return (NULL); t->root = NULL; @@ -509,7 +509,7 @@ int c_avl_insert (c_avl_tree_t *t, void *key, void *value) c_avl_node_t *nptr; int cmp; - if ((new = (c_avl_node_t *) malloc (sizeof (c_avl_node_t))) == NULL) + if ((new = malloc (sizeof (*new))) == NULL) return (-1); new->key = key; @@ -652,6 +652,7 @@ int c_avl_pick (c_avl_tree_t *t, void **key, void **value) *value = n->value; free_node (n); + --t->size; rebalance (t, p); return (0); @@ -664,10 +665,9 @@ c_avl_iterator_t *c_avl_get_iterator (c_avl_tree_t *t) if (t == NULL) return (NULL); - iter = (c_avl_iterator_t *) malloc (sizeof (c_avl_iterator_t)); + iter = calloc (1, sizeof (*iter)); if (iter == NULL) return (NULL); - memset (iter, '\0', sizeof (c_avl_iterator_t)); iter->tree = t; return (iter);