diff options
author | Tom Lane | 2018-08-16 17:01:09 +0000 |
---|---|---|
committer | Tom Lane | 2018-08-16 17:01:09 +0000 |
commit | e1d19c902e59ad739cb4b6267ee2073a61e86cd3 (patch) | |
tree | e6090aad9384ba77d324694e2553d02e1d0b7566 /configure | |
parent | 1eb9221585c25cad1a563bc3414f697dae3fbc8b (diff) |
Require a C99-compliant snprintf(), and remove related workarounds.
Since our substitute snprintf now returns a C99-compliant result,
there's no need anymore to have complicated code to cope with pre-C99
behavior. We can just make configure substitute snprintf.c if it finds
that the system snprintf() is pre-C99. (Note: I do not believe that
there are any platforms where this test will trigger that weren't
already being rejected due to our other C99-ish feature requirements for
snprintf. But let's add the check for paranoia's sake.) Then, simplify
the call sites that had logic to cope with the pre-C99 definition.
I also dropped some stuff that was being paranoid about the possibility
of snprintf overrunning the given buffer. The only reports we've ever
heard of that being a problem were for Solaris 7, which is long dead,
and we've sure not heard any reports of these assertions triggering in
a long time. So let's drop that complexity too.
Likewise, drop some code that wasn't trusting snprintf to set errno
when it returns -1. That would be not-per-spec, and again there's
no real reason to believe it is a live issue, especially not for
snprintfs that pass all of configure's feature checks.
Discussion: https://postgr.es/m/17245.1534289329@sss.pgh.pa.us
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 46 |
1 files changed, 45 insertions, 1 deletions
@@ -16142,7 +16142,7 @@ fi # Run tests below here # -------------------- -# Force use of our snprintf if system's doesn't do arg control +# For NLS, force use of our snprintf if system's doesn't do arg control. # See comment above at snprintf test for details. if test "$enable_nls" = yes -a "$pgac_need_repl_snprintf" = no; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf supports argument control" >&5 @@ -16436,6 +16436,50 @@ $as_echo "$pgac_cv_snprintf_size_t_support" >&6; } fi fi +# Force use of our snprintf if the system's doesn't handle buffer overrun +# as specified by C99. +if test "$pgac_need_repl_snprintf" = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether snprintf reports buffer overrun per C99" >&5 +$as_echo_n "checking whether snprintf reports buffer overrun per C99... " >&6; } +if ${pgac_cv_snprintf_c99_result+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + pgac_cv_snprintf_c99_result=cross +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <stdio.h> +#include <string.h> + +int main() +{ + char buf[10]; + + if (snprintf(buf, sizeof(buf), "12345678901234567890") != 20) + return 1; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + pgac_cv_snprintf_c99_result=yes +else + pgac_cv_snprintf_c99_result=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_snprintf_c99_result" >&5 +$as_echo "$pgac_cv_snprintf_c99_result" >&6; } + + if test "$pgac_cv_snprintf_c99_result" != yes; then + pgac_need_repl_snprintf=yes + fi +fi + # Now we have checked all the reasons to replace snprintf if test $pgac_need_repl_snprintf = yes; then |