From: Eric Biggers Date: Sun, 29 Jan 2017 05:18:21 +0000 (-0800) Subject: avl_tree.h: avoid bad function pointer cast X-Git-Tag: v1.12.0~16 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=8c27aef8836800bd83d92cad6b994ed1fea5891e avl_tree.h: avoid bad function pointer cast Casting the type of the 'cmp' function, while under normal circumstances compiled correctly, was not technically correct and was not compatible with some control flow integrity (CFI) implementations. --- diff --git a/include/wimlib/avl_tree.h b/include/wimlib/avl_tree.h index ed615edc..b7a9bb1b 100644 --- a/include/wimlib/avl_tree.h +++ b/include/wimlib/avl_tree.h @@ -145,10 +145,18 @@ avl_tree_lookup_node(const struct avl_tree_node *root, int (*cmp)(const struct avl_tree_node *, const struct avl_tree_node *)) { - return avl_tree_lookup(root, - (const void *)node, - (int (*) (const void *, - const struct avl_tree_node *))cmp); + const struct avl_tree_node *cur = root; + + while (cur) { + int res = (*cmp)(node, cur); + if (res < 0) + cur = cur->left; + else if (res > 0) + cur = cur->right; + else + break; + } + return (struct avl_tree_node*)cur; } /*