Re: [PATCH v1 05/48] tools lib: Silence -Wshorten-64-to-32 warnings

From: Yury Norov
Date: Thu Apr 03 2025 - 10:26:44 EST


On Tue, Apr 01, 2025 at 11:23:03AM -0700, Ian Rogers wrote:
> The clang warning -Wshorten-64-to-32 can be useful to catch
> inadvertent truncation. In some instances this truncation can lead to
> changing the sign of a result, for example, truncation to return an
> int to fit a sort routine. Silence the warning by making the implicit
> truncation explicit.
>
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> ---

...

> diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
> index 2178862bb114..87bd15e3968e 100644
> --- a/tools/lib/bitmap.c
> +++ b/tools/lib/bitmap.c
> @@ -32,7 +32,7 @@ size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits,
> char *buf, size_t size)
> {
> /* current bit is 'cur', most recently seen range is [rbot, rtop] */
> - unsigned int cur, rbot, rtop;
> + size_t cur, rbot, rtop;
> bool first = true;
> size_t ret = 0;

Maybe instead typecast find_next_bit()? We don't expect any of those
to overflow the 'unsigned int'.

Thanks,
Yury