From ea98c65f5f6a100300e452a5a3ab800d566c41c4 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 24 Dec 2010 10:13:43 +0100 Subject: [PATCH] *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. --- ChangeLog | 22 ++++++++++++++++++++++ doc/posix-functions/dprintf.texi | 5 ----- doc/posix-functions/fprintf.texi | 10 +++++----- doc/posix-functions/printf.texi | 10 +++++----- doc/posix-functions/snprintf.texi | 10 +++++----- doc/posix-functions/sprintf.texi | 10 +++++----- doc/posix-functions/vdprintf.texi | 5 ----- doc/posix-functions/vfprintf.texi | 10 +++++----- doc/posix-functions/vprintf.texi | 10 +++++----- doc/posix-functions/vsnprintf.texi | 10 +++++----- doc/posix-functions/vsprintf.texi | 10 +++++----- m4/printf.m4 | 12 ++++++++---- tests/test-snprintf-posix.h | 13 +++++++++++++ tests/test-sprintf-posix.h | 13 +++++++++++++ tests/test-vasnprintf-posix.c | 15 +++++++++++++++ tests/test-vasprintf-posix.c | 15 +++++++++++++++ 16 files changed, 126 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 97909feba..038e38bbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2010-12-24 Bruno Haible + + *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. + 2010-12-23 Paul Eggert tests: port test-fdutimensat.c to Solaris 8 diff --git a/doc/posix-functions/dprintf.texi b/doc/posix-functions/dprintf.texi index 3f9f54b62..dc3902292 100644 --- a/doc/posix-functions/dprintf.texi +++ b/doc/posix-functions/dprintf.texi @@ -24,9 +24,4 @@ glibc-2.3.6. 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 diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi index 116d20e13..e922e85e0 100644 --- a/doc/posix-functions/fprintf.texi +++ b/doc/posix-functions/fprintf.texi @@ -55,6 +55,11 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 @@ mingw. 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 diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi index fb894d6f4..eaee96a75 100644 --- a/doc/posix-functions/printf.texi +++ b/doc/posix-functions/printf.texi @@ -55,6 +55,11 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 @@ mingw. 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 diff --git a/doc/posix-functions/snprintf.texi b/doc/posix-functions/snprintf.texi index 5d19ccf11..aa3280862 100644 --- a/doc/posix-functions/snprintf.texi +++ b/doc/posix-functions/snprintf.texi @@ -69,6 +69,11 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 @@ OSF/1 5.1. 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 diff --git a/doc/posix-functions/sprintf.texi b/doc/posix-functions/sprintf.texi index cce962762..ad6671f6b 100644 --- a/doc/posix-functions/sprintf.texi +++ b/doc/posix-functions/sprintf.texi @@ -55,15 +55,15 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 diff --git a/doc/posix-functions/vdprintf.texi b/doc/posix-functions/vdprintf.texi index 3fa9b737a..20a6ef75c 100644 --- a/doc/posix-functions/vdprintf.texi +++ b/doc/posix-functions/vdprintf.texi @@ -42,9 +42,4 @@ BeOS. 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 diff --git a/doc/posix-functions/vfprintf.texi b/doc/posix-functions/vfprintf.texi index 7f41c0d55..7e502347d 100644 --- a/doc/posix-functions/vfprintf.texi +++ b/doc/posix-functions/vfprintf.texi @@ -55,6 +55,11 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 @@ mingw. 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 diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi index 213461c9f..526070e22 100644 --- a/doc/posix-functions/vprintf.texi +++ b/doc/posix-functions/vprintf.texi @@ -55,6 +55,11 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 @@ mingw. 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 diff --git a/doc/posix-functions/vsnprintf.texi b/doc/posix-functions/vsnprintf.texi index 38266a01e..2ea98cbb9 100644 --- a/doc/posix-functions/vsnprintf.texi +++ b/doc/posix-functions/vsnprintf.texi @@ -69,6 +69,11 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 @@ HP-UX 11, OSF/1 5.1. 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 diff --git a/doc/posix-functions/vsprintf.texi b/doc/posix-functions/vsprintf.texi index 317853885..39203d0d3 100644 --- a/doc/posix-functions/vsprintf.texi +++ b/doc/posix-functions/vsprintf.texi @@ -55,15 +55,15 @@ This function does not support precisions larger than 512 or 1024 in integer, 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 diff --git a/m4/printf.m4 b/m4/printf.m4 index 8cffa6ad2..6c8a7a45b 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -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 @@ changequote([,])dnl 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 @@ int main () 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.25 (2008) . . . # # . . # . . . . . # . 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 # . # # # # . . . . . # . . . . # . . . diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 37612f9ef..b2a0ebef9 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -3045,6 +3045,19 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { + 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; diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index ff162aa87..35451da50 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -3031,6 +3031,19 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { + 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; diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index dd98691ad..44f262fdc 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -3568,6 +3568,21 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { + 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; diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index 8f71c4f97..5b586ad7e 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -3548,6 +3548,21 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { + 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; -- 2.11.0