That just leaves the question of whether we can give the compiler enough hints for it to come to the same conclusion, or whether we'd only be able to shut it up with a sledgehammer preprocessor directive.
I'm puzzled as to how/why this check is even being run.
I've just built perl-5.33.2 with the usual configure args , making no attempt to influence the setting of Gconvert.
But I've applied this patch to sv.c:
--- sv.c 2020-09-29 22:29:16.781395700 +1000
+++ sv.c_mod 2020-10-02 11:35:20.728840400 +1000
@@ -13115,7 +13115,7 @@
&& intsize != 'q'
) {
WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric,
- SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis)
+ PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
);
elen = strlen(ebuf);
eptr = ebuf;
That works fine but I'm not happy about the double-rounding that takes place when nvtype is 'double' 'long double'.
We really want fv to be an NV, not a long double.
And then we would need the sprintf() formatting to accommodate the nvtype - "g" versus "Lg".
UPDATE: Duh ... there is no double-rounding ... but I think I still need to attend to the issue of "g" or "Lg" formatting.
And it still produces that awful noise (see below my sig).
The command that produces that noise is:
cc -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector
+-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=
+64 -std=c89 -O2 -Wall -Werror=pointer-arith -Wextra -Wc++-compat -Wwr
+ite-strings -Werror=declaration-after-statement sv.c
So I've tried (unsuccessfully) to reproduce those warnings by compiling the following C program:
#include <stdio.h>
int main(void) {
char ebuf[127];
long double fv = 0.3L;
int precis = 54;
sprintf(ebuf, "%.*g", precis, (double) fv);
printf("%s\n", ebuf);
return 0;
}
I compiled it by running the same command (minus the perl-specific "-D..." switches) and it compiles noiselessly.
So I guess that the noise must be introduced by something in those perl-specific switches.
Do you know how to reproduce the warnings when compiling that C script ?
Incidentally, AFAICS, that patch effectively removes Gconvert from the perl source entirely - except for Win32API-File, where the Gconvert call in cpan\Win32API-File\const2perl.h could be replaced with sprintf(), anyway.
For Windows, Gconvert is already hard coded to sprintf().
Cheers, Rob
In file included from sv.c:32:0:
sv.c: In function ‘Perl_sv_vcatpvfn_flags’:
sv.c:13118:54: warning: ‘%.*g’ directive writing between 1 and 133 byt
+es into a region of size 127 [-Wformat-overflow=]
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
perl.h:6791:13: note: in definition of macro ‘WITH_LC_NUMERIC_SET_TO_N
+EEDED_IN’
block;
+ \
^~~~~
sv.c:13118:21: note: in expansion of macro ‘PERL_UNUSED_RESULT’
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
sv.c:13118:54: note: assuming directive output of 132 bytes
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
perl.h:6791:13: note: in definition of macro ‘WITH_LC_NUMERIC_SET_TO_N
+EEDED_IN’
block;
+ \
^~~~~
sv.c:13118:21: note: in expansion of macro ‘PERL_UNUSED_RESULT’
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
In file included from /usr/include/stdio.h:862:0,
from perlio.h:41,
from iperlsys.h:50,
from perl.h:3934,
from sv.c:32:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘__builtin___
+sprintf_chk’ output between 2 and 134 bytes into a destination of siz
+e 127
return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from sv.c:32:0:
sv.c:13118:54: warning: ‘%.*g’ directive writing between 1 and 133 byt
+es into a region of size 127 [-Wformat-overflow=]
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
perl.h:6791:13: note: in definition of macro ‘WITH_LC_NUMERIC_SET_TO_N
+EEDED_IN’
block;
+ \
^~~~~
sv.c:13118:21: note: in expansion of macro ‘PERL_UNUSED_RESULT’
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
sv.c:13118:54: note: assuming directive output of 132 bytes
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
perl.h:6791:13: note: in definition of macro ‘WITH_LC_NUMERIC_SET_TO_N
+EEDED_IN’
block;
+ \
^~~~~
sv.c:13118:21: note: in expansion of macro ‘PERL_UNUSED_RESULT’
PERL_UNUSED_RESULT(sprintf(ebuf, "%.*g", (int)pre
+cis, (NV) fv))
^
In file included from /usr/include/stdio.h:862:0,
from perlio.h:41,
from iperlsys.h:50,
from perl.h:3934,
from sv.c:32:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘__builtin___
+sprintf_chk’ output between 2 and 134 bytes into a destination of siz
+e 127
return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
|