Hi Jeffrey,
On Thu, May 02, 2019 at 12:46:30PM -0400, Jeffrey Walton wrote:
> On Thu, May 2, 2019 at 12:02 PM Mark Wielaard <[email protected]> wrote:
> >
> > On Tue, 2019-04-30 at 20:43 -0400, Jeffrey Walton wrote:
> > > It looks like GCC has one squawk:
> > >
> > > vgdb.c: In function ‘standalone_send_commands’:
> > > vgdb.c:1008:21: warning: ‘%02x’ directive writing between 2 and 8
> > > bytes into a r
> > > egion of size 3 [-Wformat-overflow=]
> > > sprintf(hex, "%02x", cksum);
> > > ^~~~
> > > vgdb.c:1008:20: note: directive argument in the range [0, 2147483647]
> > > sprintf(hex, "%02x", cksum);
> > > ^~~~~~
> >
> > But cksum is an unsigned char, so value is be between [0, 255]. Which
> > is max 2 hex chars.
> >
> > Could you retry with GCC8 or GCC9?
> > And file a bug against GCC otherwise?
>
> If Valgrind is interested in working around it without increasing the
> buffer size, then the format string "%.2x" should do the trick.
Although I appreciate having zero warning builds, I do believe this
should be filed and tracked in gcc. Or better understood why the
warning is triggering for you. I have been unable to trigger the
warning with GCC 7.3.1 on either amd64 or i686. So I am wondering if
it is somehow arm specific? (Does arm have signed or unsigned char by
default? Does that matter?) Also the fact that it does trigger with
"%02x", but not "%.2x" is suspecious IMHO. Both should indicate that
the value is at least 2 chars, but maybe more. So why does one trigger
the warning, but not the other?
> $ cat test.c
> #include
Missing stdio.h ?
> int main(int argc, char* argv[])
> {
> char buf[3];
> sprintf(buf, "%.2x", (unsigned char)argc);
> printf("%s\n", buf);
> return 0;
> }
>
> And:
>
> $ gcc -Wall -Wformat-overflow=2 test.c -o test.exe
And I assume on your system this produces a warning replacing '.' with
'0'? I have been unable to trigger the warning with GCC 7.3.1 and GCC
8.2.1 (on x86_64 with or without -m32). So I wonder where/when it does
trigger.
Cheers,
Mark
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users