Re: [PATCH v2] x86/lib: Optimize num_digits() and fix INT_MIN overflow

From: H. Peter Anvin

Date: Tue Jan 20 2026 - 19:18:53 EST


On 2026-01-20 16:04, David Desobry wrote:
>
> Actually, the V3 change:    
> if (val < 0) {
> -        d++;
> -        val = -val;
> +        d = 1;
> +        v = -val;
> +    } else {
> +        d = 0;
> +        v = val;
>      }
> reintroduced the undefined behavior for val == INT_MIN.
> So this V3 version is incorrect.
> I'm not familiar enough with the rest of the codebase to know if changing the
> function signature to unsigned int is correct here.

It is only ever called with a cpu number, a node number, or a CPU count. Never
negative.

-hpa