This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c13761842af22e81704d7f02750a5599d461f33b Author: ouyangxiangzhen <[email protected]> AuthorDate: Wed Nov 4 20:07:11 2026 +0800 lib/math32: widen div64_const() base to 64-bit div64_const() took uint32_t base, silently truncating any wider divisor: div_const(n, 1ULL << 40) passed 0 as the divisor and divided by zero at runtime. Widen the parameter to uint64_t and handle the full range: - Compute the power-of-two shift count with LOG2_FLOOR(), which is 64-bit safe on all hosts (see the previous commit). - Call div64_const32() only when base actually fits in 32 bits (explicitly narrowed); larger divisors fall back to plain division. - Assert the divisor contract (base > 0) at entry. Widening the parameter is source compatible with existing callers. Assisted-By: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <[email protected]> --- include/nuttx/lib/math32.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/nuttx/lib/math32.h b/include/nuttx/lib/math32.h index dcfe72c4cd7..5e6a2040c99 100644 --- a/include/nuttx/lib/math32.h +++ b/include/nuttx/lib/math32.h @@ -320,15 +320,17 @@ static inline_function uint64_t div64_const32(uint64_t n, uint32_t b) return res; } -static inline_function uint64_t div64_const(uint64_t n, uint32_t base) +static inline_function uint64_t div64_const(uint64_t n, uint64_t base) { + DEBUGASSERT(base > 0); + if (IS_POWER_OF_2(base)) { n >>= LOG2_FLOOR(base); } - else if (UINTPTR_MAX == UINT32_MAX) + else if (base <= UINT32_MAX) { - n = div64_const32(n, base); + n = div64_const32(n, (uint32_t)base); } else {
