Hello Paul, > This prints "513 0.0...." rather than the correct "513 1.0....".
Indeed. I reproduce on Solaris 10/SPARC. On Solaris 10/x86, the result is simply a SIGSEGV. When I build a testdir for 'snprintf-posix', the results are: - On Solaris 10/x86: checking whether printf supports large precisions... no checking whether printf survives out-of-memory conditions... no REPLACE_SNPRINTF is 1. All tests pass. - On Solaris 10/sparc: checking whether printf supports large precisions... yes checking whether printf survives out-of-memory conditions... yes REPLACE_SNPRINTF is 1. test-snprintf-posix fails: test-snprintf-posix.h:3039: assertion failed bash: line 5: 2924 Abort (core dumped) EXEEXT='' srcdir='.' MAKE='make' ${dir}$tst FAIL: test-snprintf-posix So the existing test whether printf supports large precisions was incomplete. I'm integrating your test case, so that configure will now say "no" on both Solaris 10/x86 and Solaris 10/sparc. > doc/posix-functions/dprintf.texi (dprintf): > doc/posix-functions/vdprintf.texi (vdprintf): You did not need to modify these files. Solaris does not have dprintf and vdprintf. I'll check in this fix: 2010-12-24 Bruno Haible <br...@clisp.org> *printf: Detect large precisions bug on Solaris 10/SPARC. * m4/printf.m4 (gl_PRINTF_PRECISION): Add one more test code, provided by Paul Eggert. * tests/test-snprintf-posix.h (test_function): Add this test code here too. * tests/test-sprintf-posix.h (test_function): Likewise. * tests/test-vasnprintf-posix.c (test_function): Likewise. * tests/test-vasprintf-posix.c (test_function): Likewise. * doc/posix-functions/fprintf.texi: Mention Solaris 10 bug as worked around by gnulib. * doc/posix-functions/printf.texi: Likewise. * doc/posix-functions/snprintf.texi: Likewise. * doc/posix-functions/sprintf.texi: Likewise. * doc/posix-functions/vfprintf.texi: Likewise. * doc/posix-functions/vprintf.texi: Likewise. * doc/posix-functions/vsnprintf.texi: Likewise. * doc/posix-functions/vsprintf.texi: Likewise. * doc/posix-functions/dprintf.texi: Undo last commit. * doc/posix-functions/vdprintf.texi: Likewise. --- doc/posix-functions/dprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/dprintf.texi Fri Dec 24 09:41:40 2010 @@ -24,9 +24,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/fprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/fprintf.texi Fri Dec 24 09:38:24 2010 @@ -55,6 +55,11 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @end itemize @@ -69,9 +74,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/printf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/printf.texi Fri Dec 24 09:39:25 2010 @@ -55,6 +55,11 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @end itemize @@ -69,9 +74,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/snprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/snprintf.texi Fri Dec 24 09:39:43 2010 @@ -69,6 +69,11 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @item @@ -89,9 +94,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/sprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/sprintf.texi Fri Dec 24 09:39:57 2010 @@ -55,15 +55,15 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @end itemize Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/vdprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/vdprintf.texi Fri Dec 24 09:41:33 2010 @@ -42,9 +42,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/vfprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/vfprintf.texi Fri Dec 24 09:40:12 2010 @@ -55,6 +55,11 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @end itemize @@ -69,9 +74,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/vprintf.texi.orig Fri Dec 24 09:56:06 2010 +++ doc/posix-functions/vprintf.texi Fri Dec 24 09:40:21 2010 @@ -55,6 +55,11 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @end itemize @@ -69,9 +74,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/vsnprintf.texi.orig Fri Dec 24 09:56:07 2010 +++ doc/posix-functions/vsnprintf.texi Fri Dec 24 09:40:36 2010 @@ -69,6 +69,11 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @item @@ -89,9 +94,4 @@ Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- doc/posix-functions/vsprintf.texi.orig Fri Dec 24 09:56:07 2010 +++ doc/posix-functions/vsprintf.texi Fri Dec 24 09:40:57 2010 @@ -55,15 +55,15 @@ floating-point and pointer output on some platforms: Solaris 10/x86, mingw, BeOS. @item +This function mishandles large floating point precisions +(for example, formatting 1.0 with @samp{"%.511f"}) +on some platforms: +Solaris 10. +...@item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. @end itemize Portability problems not fixed by Gnulib: @itemize -...@item -This function mishandles large floating point precisions -(for example, formatting 1.0 with @samp{"%.511f"}) -on some platforms: -Solaris 10. @end itemize --- m4/printf.m4.orig Fri Dec 24 09:56:07 2010 +++ m4/printf.m4 Fri Dec 24 09:29:56 2010 @@ -1,4 +1,4 @@ -# printf.m4 serial 41 +# printf.m4 serial 42 dnl Copyright (C) 2003, 2007-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -890,8 +890,9 @@ dnl Test whether the *printf family of functions supports large precisions. dnl On mingw, precisions larger than 512 are treated like 512, in integer, dnl floating-point or pointer output. On Solaris 10/x86, precisions larger -dnl than 510 in floating-point output crash the program. On BeOS, precisions -dnl larger than 1044 crash the program. +dnl than 510 in floating-point output crash the program. On Solaris 10/SPARC, +dnl precisions larger than 510 in floating-point output yield wrong results. +dnl On BeOS, precisions larger than 1044 crash the program. dnl Result is gl_cv_func_printf_precision. AC_DEFUN([gl_PRINTF_PRECISION], @@ -917,6 +918,9 @@ result |= 1; if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5) result |= 2; + if (sprintf (buf, "%.511f %d", 1.0, 33, 44) < 511 + 5 + || buf[0] != '1') + result |= 4; return result; }]])], [gl_cv_func_printf_precision=yes], @@ -1459,7 +1463,7 @@ dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . dnl Solaris 11 2010-11 . . # # # . . # . . . # . . . . . . . . dnl Solaris 10 . . # # # . . # . . . # # . . . . . . . -dnl Solaris 2.6 ... 9 # . # # # # . # . . . # . . . . # . . . +dnl Solaris 2.6 ... 9 # . # # # # . # . . . # # . . . # . . . dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # dnl AIX 5.2, 7.1 . . # # # . . . . . . # . . . . . . . . dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . # . . . --- tests/test-snprintf-posix.h.orig Fri Dec 24 09:56:07 2010 +++ tests/test-snprintf-posix.h Fri Dec 24 09:32:48 2010 @@ -3045,6 +3045,19 @@ } { + char result[1000]; + int retval = + my_snprintf (result, sizeof (result), "%.511f %d", 1.0, 99); + size_t i; + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 511; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 511, " 99") == 0); + ASSERT (retval == strlen (result)); + } + + { char input[5000]; char result[5000]; int retval; --- tests/test-sprintf-posix.h.orig Fri Dec 24 09:56:07 2010 +++ tests/test-sprintf-posix.h Fri Dec 24 09:31:28 2010 @@ -3031,6 +3031,19 @@ } { + char result[1000]; + int retval = + my_sprintf (result, "%.511f %d", 1.0, 99); + size_t i; + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 511; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 511, " 99") == 0); + ASSERT (retval == strlen (result)); + } + + { char input[5000]; char result[5000]; int retval; --- tests/test-vasnprintf-posix.c.orig Fri Dec 24 09:56:07 2010 +++ tests/test-vasnprintf-posix.c Fri Dec 24 09:32:11 2010 @@ -3568,6 +3568,21 @@ } { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%.511f %d", 1.0, 99); + size_t i; + ASSERT (result != NULL); + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 511; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 511, " 99") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { char input[5000]; size_t length; char *result; --- tests/test-vasprintf-posix.c.orig Fri Dec 24 09:56:07 2010 +++ tests/test-vasprintf-posix.c Fri Dec 24 09:31:52 2010 @@ -3548,6 +3548,21 @@ } { + char *result; + int retval = + my_asprintf (&result, "%.511f %d", 1.0, 99); + size_t i; + ASSERT (result != NULL); + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 511; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 511, " 99") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { char input[5000]; char *result; int retval;