[HACKERS] new gcc 7.0.1 warnings
[HACKERS] new gcc 7.0.1 warnings
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
Hi
I am checking new Fedora 26, where new gcc compiler is used.
float.c: In function ‘float4out’:
float.c:382:41: warning: ‘%.*g’ directive output may be truncated writing between 1 and 310 bytes into a region of size 65 [-Wformat-truncation=]
snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num);
^~~~
float.c:382:5: note: ‘snprintf’ output between 2 and 311 bytes into a destination of size 65
snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float.c: In function ‘float8out_internal’:
float.c:618:42: warning: ‘%.*g’ directive output may be truncated writing between 1 and 310 bytes into a region of size 129 [-Wformat-truncation=]
snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
^~~~
float.c:618:5: note: ‘snprintf’ output between 2 and 311 bytes into a destination of size 129
snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Regards
Pavel
Re: [HACKERS] new gcc 7.0.1 warnings
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Pavel Stehule writes:
> float.c:382:5: note: ‘snprintf’ output between 2 and 311 bytes into a
> destination of size 65
> float.c:618:5: note: ‘snprintf’ output between 2 and 311 bytes into a
> destination of size 129
That's kind of annoying. I suppose the point is that the compiler can't
see what precision we're selecting, and with sufficiently large precision
the output could be that wide. But actually the precision should be small
enough to make that OK.
Do the warnings go away if you add some explicit guard to the precision
variable, say like this:
{ int ndig = DBL_DIG + extra_float_digits;
if (ndig < 1) ndig = 1;
+ if (ndig > 50)
+ ndig = 50;
snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num); }
If not, I guess we could increase the size of the palloc'd strings,
but that seems wasteful.
regards, tom lane
Re: [HACKERS] new gcc 7.0.1 warnings
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-02-18 18:35 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
Pavel Stehule <pavel.stehule@gmail.com> writes:
> float.c:382:5: note: ‘snprintf’ output between 2 and 311 bytes into a
> destination of size 65
> float.c:618:5: note: ‘snprintf’ output between 2 and 311 bytes into a
> destination of size 129
That's kind of annoying. I suppose the point is that the compiler can't
see what precision we're selecting, and with sufficiently large precision
the output could be that wide. But actually the precision should be small
enough to make that OK.
Do the warnings go away if you add some explicit guard to the precision
variable, say like this:
{
int ndig = DBL_DIG + extra_float_digits;
if (ndig < 1)
ndig = 1;
+ if (ndig > 50)
+ ndig = 50;
This fix doesn't help
Regards
Pavel
snprintf(ascii, MAXDOUBLEWIDTH + 1, "%.*g", ndig, num);
}
If not, I guess we could increase the size of the palloc'd strings,
but that seems wasteful.
regards, tom lane
Re: [HACKERS] new gcc 7.0.1 warnings
От:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Дата:
On 2/18/17 02:08, Pavel Stehule wrote: > I am checking new Fedora 26, where new gcc compiler is used. > > float.c: In function ‘float4out’: > float.c:382:41: warning: ‘%.*g’ directive output may be truncated > writing between 1 and 310 bytes into a region of size 65 > [-Wformat-truncation=] > snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num); It appears these warnings no longer happen with a newer gcc-7 snapshot. I'm using gcc-7 (Debian 7-20170302-1) 7.0.1 20170302 (experimental) [trunk revision 245832] -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] new gcc 7.0.1 warnings
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-03-08 16:59 GMT+01:00 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:
gcc (GCC) 7.0.1 20170225 is on Fc still :(
On 2/18/17 02:08, Pavel Stehule wrote:
> I am checking new Fedora 26, where new gcc compiler is used.
>
> float.c: In function ‘float4out’:
> float.c:382:41: warning: ‘%.*g’ directive output may be truncated
> writing between 1 and 310 bytes into a region of size 65
> [-Wformat-truncation=]
> snprintf(ascii, MAXFLOATWIDTH + 1, "%.*g", ndig, num);
It appears these warnings no longer happen with a newer gcc-7 snapshot.
I'm using
gcc-7 (Debian 7-20170302-1) 7.0.1 20170302 (experimental) [trunk
revision 245832]
Regards
Pavel
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] new gcc 7.0.1 warnings
От:
Alvaro Herrera <alvherre@2ndquadrant.com>
Дата:
Pavel Stehule wrote:
> 2017-02-18 18:35 GMT+01:00 Tom Lane :
>
> > Pavel Stehule writes:
> > Do the warnings go away if you add some explicit guard to the precision
> > variable, say like this:
> >
> > {
> > int ndig = DBL_DIG + extra_float_digits;
> >
> > if (ndig < 1)
> > ndig = 1;
> > + if (ndig > 50)
> > + ndig = 50;
>
> This fix doesn't help
Ahh, so this is why you had this change in the xmltable patch once!
Heh. Please be more careful.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Re: [HACKERS] new gcc 7.0.1 warnings
От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
2017-03-08 17:33 GMT+01:00 Alvaro Herrera <alvherre@2ndquadrant.com>:
Pavel Stehule wrote:
> 2017-02-18 18:35 GMT+01:00 Tom Lane <tgl@sss.pgh.pa.us>:
>
> > Pavel Stehule <pavel.stehule@gmail.com> writes:
> > Do the warnings go away if you add some explicit guard to the precision
> > variable, say like this:
> >
> > {
> > int ndig = DBL_DIG + extra_float_digits;
> >
> > if (ndig < 1)
> > ndig = 1;
> > + if (ndig > 50)
> > + ndig = 50;
>
> This fix doesn't help
Ahh, so this is why you had this change in the xmltable patch once!
Heh. Please be more careful.
grr :(
I am sorry
Pavel
--
Álvaro Herrera https://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services