From e61fe7b4514fe14a5384500f0b703fcd4c96b9ab Mon Sep 17 00:00:00 2001 From: John Sanpe Date: Fri, 3 Jan 2025 04:01:35 +0800 Subject: [PATCH] fixup radix: fixed radix iterators arithmetic issue Signed-off-by: John Sanpe --- src/radix.c | 14 ++++++++------ src/rbtree.c | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/radix.c b/src/radix.c index c29b3522..3f8fe633 100644 --- a/src/radix.c +++ b/src/radix.c @@ -402,15 +402,16 @@ bfdev_radix_root_next(bfdev_radix_root_t *root, uintptr_t *offsetp) node = parents[level].node; index = parents[level].index; + count = radix_depth_shift(level - 1); + *offsetp &= ~((uintptr_t)RADIX_ARY_MASK << count); + while (++index < BFDEV_RADIX_ARY) { if (!node->child[index]) continue; - count = radix_depth_shift(level - 1); - *offsetp &= ~((uintptr_t)RADIX_ARY_MASK << count); *offsetp |= (uintptr_t)index << count; - node = node->child[index]; + goto downward; } } @@ -457,15 +458,16 @@ bfdev_radix_root_prev(bfdev_radix_root_t *root, uintptr_t *offsetp) node = parents[level].node; index = parents[level].index; + count = radix_depth_shift(level - 1); + *offsetp &= ~((uintptr_t)RADIX_ARY_MASK << count); + while (index--) { if (!node->child[index]) continue; - count = radix_depth_shift(level - 1); - *offsetp &= ~((uintptr_t)RADIX_ARY_MASK << count); *offsetp |= (uintptr_t)index << count; - node = node->child[index]; + goto downward; } } diff --git a/src/rbtree.c b/src/rbtree.c index 581abfd6..1a5431d6 100644 --- a/src/rbtree.c +++ b/src/rbtree.c @@ -542,8 +542,7 @@ bfdev_rb_replace(bfdev_rb_root_t *root, bfdev_rb_node_t *oldn, } export bfdev_rb_node_t * -bfdev_rb_find(const bfdev_rb_root_t *root, void *key, - bfdev_rb_find_t find) +bfdev_rb_find(const bfdev_rb_root_t *root, void *key, bfdev_rb_find_t find) { bfdev_rb_node_t *node; long retval;