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.
int (*cmp)(const struct avl_tree_node *,
const struct avl_tree_node *))
{
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;