raw_clz64() always operates on uint64_t, so it counts leading zeros
from bit 63. The original expression used (BITMAP_ULONG_BITS - 1)
which is 31 on 32-bit architectures where unsigned long is 32 bits.
When a 32-bit value is implicitly promoted to uint64_t, raw_clz64()
returns a value 32 higher than expected, making the subtraction
produce incorrect (negative) results.
Use the constant 63 to match raw_clz64()'s 64-bit input width.
Fixes: 39eb5b573388 ("Add sparse array.")
Assisted-by: Claude, with model: claude-opus-4-6
Signed-off-by: Dumitru Ceara <[email protected]>
---
NOTE: 32-bit OVN deployments are unlikely to exist in the wild, but
this fix ensures correctness in case someone attempts to build OVN
for a 32-bit target.
---
lib/ovn-util.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/ovn-util.h b/lib/ovn-util.h
index bcb344de44..b44c9c770a 100644
--- a/lib/ovn-util.h
+++ b/lib/ovn-util.h
@@ -549,8 +549,8 @@ dynamic_bitmap_last_set(const struct dynamic_bitmap *db)
continue;
}
- return (BITMAP_ULONG_BITS - 1) - raw_clz64(db->map[i])
- + (BITMAP_ULONG_BITS * i);
+ /* raw_clz64() operates on values promoted to uint64_t (64-bit). */
+ return 63 - raw_clz64(db->map[i]) + (BITMAP_ULONG_BITS * i);
}
return -1;
--
2.53.0
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev