RE: [PATCH] objtool: Fix -Wformat-truncation seen with GCC 12.

From: David Laight
Date: Wed Jan 12 2022 - 04:38:44 EST


From: Martin Liška
> Sent: 12 January 2022 09:29
>
> The patch fixes the following warning that seems reasonable:
>
> check.c:2836:58: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a
> region of size 9 [-Werror=format-truncation=]
> 2836 | snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);

Looks pretty unreasonable to me :-)
The domain of 'idx' is much smaller than that of 'int'.
Indeed the overflow can only actually happen if it is negative.
By then all sorts of other things will have gone wrong.

OTOH changing 16 to 60 is one way to STFU.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)