new gcc 7.0.1 warnings

Started by Pavel Stehulealmost 9 years ago7 messages
#1Pavel 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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#1)
Re: new gcc 7.0.1 warnings

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;

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Tom Lane (#2)
Re: new gcc 7.0.1 warnings

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

Show quoted text

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

#4Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Pavel Stehule (#1)
Re: new gcc 7.0.1 warnings

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Peter Eisentraut (#4)
Re: new gcc 7.0.1 warnings

2017-03-08 16:59 GMT+01:00 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]

gcc (GCC) 7.0.1 20170225 is on Fc still :(

Regards

Pavel

Show quoted text

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#6Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Pavel Stehule (#3)
Re: new gcc 7.0.1 warnings

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.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Pavel Stehule
pavel.stehule@gmail.com
In reply to: Alvaro Herrera (#6)
Re: new gcc 7.0.1 warnings

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

Show quoted text

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services