[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241220172920.7a34eb46@dsl-u17-10>
Date: Fri, 20 Dec 2024 17:29:20 +0000
From: David Laight <david.laight.linux@...il.com>
To: Guenter Roeck <linux@...ck-us.net>
Cc: kernel test robot <lkp@...el.com>, Eddie James <eajames@...ux.ibm.com>,
oe-kbuild-all@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: drivers/hwmon/pmbus/ibm-cffps.c:184:60: warning: '%04X'
directive output may be truncated writing between 4 and 8 bytes into a
region of size 5
On Fri, 20 Dec 2024 09:03:51 -0800
Guenter Roeck <linux@...ck-us.net> wrote:
> On 12/20/24 08:30, David Laight wrote:
...
> >>
> >>> drivers/hwmon/pmbus/ibm-cffps.c:171:60: warning: '%02X' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Wformat-truncation=]
> >>> 171 | snprintf(&data[i * 2], 3, "%02X", rc);
> >
> > The only ways I know are to bound check the value or to use
> > OPTIMISER_HIDE_VAR() on the length.
> >
>
> - snprintf(&data[i * 2], 3, "%02X", rc);
> + snprintf(&data[i * 2], 3, "%02X", rc & 0xff);
>
> works as well, at least with gcc 11 and 12, but I really dislike that kind of nonsense.
Ditto.
Using the result in some ways can also remove the warning.
But you have to try quite hard, a simple (void) really ought to be
enough to show you 'just don't care' but even 'if (snprintf(...)) {}'
isn't enough (it does silence 'warn-unused-result').
I mean, the whole point of snprintf() is that it truncates.
David
Powered by blists - more mailing lists