format-truncation

Segher Boessenkool segher@kernel.crashing.org
Thu Feb 14 15:21:00 GMT 2019


On Thu, Feb 14, 2019 at 11:08:26AM +0000, Jonathan Wakely wrote:
> On Thu, 14 Feb 2019 at 10:52, Kalamatee <kalamatee@gmail.com> wrote:
> >
> > it is used by acpica to implement snprintf and sprint -:
> >
> > https://github.com/acpica/acpica/blob/master/source/components/utilities/utprint.c
> >
> > see line 837.
> >
> > Clearly Format and Args aren't known at compile time, however the invocation is correct and valid so I don't get why the incorrect warning is shown.
> >
> > (I could understand a message similar to other -format ones that suggest the operation may overflow the buffer - but that's not what the diagnostic says, it implies the second parameter cant be over INT_MAX).
> 
> It doesn't say it can't be over INT_MAX, it just warns you that it is
> over INT_MAX (because that means no checking on the output length).

That does mean it does not belong in -Wformat-truncation=1 (which is what
we have here).  It does not belong in -Wall.  It will warn for all valid
code that uses this language feature!  And it isn't necessarily a
questionable feature.  Also, the documentation for =1 says this warns for
"calls [...] that will most likely result in output truncation", which
isn't true here, one hopes.


Segher



More information about the Gcc-help mailing list