|WARNING| bitops: fix integer overflow in align64pow2
dpdklab at iol.unh.edu
dpdklab at iol.unh.edu
Fri Nov 13 22:42:15 CET 2026
Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172878
_AI Code Review_
=== Patch Review: series.patch (via Claude) ===
Review date: 2026-11-13
**Errors**
1. **Input 0 now returns `UINT64_MAX` instead of 0.**
The function begins with `v--;`, so `rte_align64pow2(0)` gives `v = UINT64_MAX` before `rte_combine64ms1b()`. That value survives the combine, and the new check then does:
```c
+ if (v == UINT64_MAX)
+ v--;
```
The function now returns `UINT64_MAX` for input 0. Before this patch it returned 0, which matches `rte_align32pow2(0)`.
Any caller that passes 0, or that uses a 0 result to detect "cannot align", now gets a huge size that is not a power of two.
2. **Inputs above 2^63 now return a non-power-of-two.**
For any `v > (1ULL << 63)`, the patched function returns `UINT64_MAX`. That value is not a power of two, so it breaks the function's contract, "smallest power of 2 >= v".
The original wrap to 0 is not undefined behaviour. `v` is `uint64_t`, so `v + 1` is well-defined modulo 2^64. A 0 result is the natural "no representable power of 2" sentinel. Callers that mask with `result - 1` or check `rte_is_power_of_2()` will now misbehave.
Suggested fix: drop the change. If the SVACE report must be silenced, document that 0 is returned when no 64-bit power of two is >= v. Do not return a value that violates the contract.
**Warnings**
3. **The fix is applied only to the 64-bit variant.**
`rte_align32pow2()` (and `rte_align32prevpow2` / `rte_align64prevpow2`, if related) have the same wrap-around pattern. Changing only the 64-bit variant makes the two families behave differently for identical edge cases.
4. **No unit test covers the boundary inputs.**
There is no test in `app/test/test_bitops.c` (or `test_common.c`, where the align tests live) for inputs 0, 1, `1ULL << 63`, `(1ULL << 63) + 1` and `UINT64_MAX`. Such a test would have exposed the regression for input 0.
Review-Result: ERROR
More information about the test-report
mailing list