From: Florian Forster Date: Wed, 17 Jun 2015 06:55:42 +0000 (+0200) Subject: src/utils_avltree.c: Rewrite checks in c_avl_pick(). X-Git-Tag: collectd-5.5.1~110^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=86ef26818f3a1af5afb4842e9c97c34ffe98bafa;p=collectd.git src/utils_avltree.c: Rewrite checks in c_avl_pick(). 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 :( --- diff --git a/src/utils_avltree.c b/src/utils_avltree.c index f71b1fd6..6a25fb57 100644 --- a/src/utils_avltree.c +++ b/src/utils_avltree.c @@ -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;