src/utils_avltree.c: Rewrite checks in c_avl_pick().
authorFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 06:55:42 +0000 (08:55 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 17 Jun 2015 06:55:44 +0000 (08:55 +0200)
The previous code made the (correct) assumption that "height" is always
greater than zero. This tripped up clang's "scan-build".

This confuses the static analysis in two more places in this file, which
are not as easy to fix :(

src/utils_avltree.c

index f71b1fd..6a25fb5 100644 (file)
@@ -613,10 +613,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;