From fb95d2ffdee15f80ca9613cf0f30828a1800a2ce Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 28 Nov 2010 01:23:57 +0100 Subject: [PATCH] *printf-posix: Detect a bug on Solaris 10/x86. * m4/printf.m4 (gl_PRINTF_PRECISION): Detect crash with large precision for floating-point output. * tests/test-vasnprintf-posix.c (test_function): Test precision with %f directive. * tests/test-snprintf-posix.h (test_function): Likewise. * tests/test-sprintf-posix.h (test_function): Likewise. * tests/test-vasprintf-posix.c (test_function): Likewise. * doc/posix-functions/fprintf.texi: Mention Solaris/x86 bug. * 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/glibc-functions/obstack_printf.texi: Likewise. * doc/glibc-functions/obstack_vprintf.texi: Likewise. --- ChangeLog | 21 +++++++++++++++++++++ doc/glibc-functions/obstack_printf.texi | 2 +- doc/glibc-functions/obstack_vprintf.texi | 2 +- doc/posix-functions/fprintf.texi | 2 +- doc/posix-functions/printf.texi | 2 +- doc/posix-functions/snprintf.texi | 2 +- doc/posix-functions/sprintf.texi | 2 +- doc/posix-functions/vfprintf.texi | 2 +- doc/posix-functions/vprintf.texi | 2 +- doc/posix-functions/vsnprintf.texi | 2 +- doc/posix-functions/vsprintf.texi | 2 +- m4/printf.m4 | 14 +++++++++----- 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, 96 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb11d9269..5d9750311 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 2010-11-27 Bruno Haible + *printf-posix: Detect a bug on Solaris 10/x86. + * m4/printf.m4 (gl_PRINTF_PRECISION): Detect crash with large precision + for floating-point output. + * tests/test-vasnprintf-posix.c (test_function): Test precision with %f + directive. + * tests/test-snprintf-posix.h (test_function): Likewise. + * tests/test-sprintf-posix.h (test_function): Likewise. + * tests/test-vasprintf-posix.c (test_function): Likewise. + * doc/posix-functions/fprintf.texi: Mention Solaris/x86 bug. + * 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/glibc-functions/obstack_printf.texi: Likewise. + * doc/glibc-functions/obstack_vprintf.texi: Likewise. + +2010-11-27 Bruno Haible + Fix link error when module libunistring-optional is in use. * modules/striconveh-tests (Makefile.am): Link with $(LIBUNISTRING). * modules/striconveha-tests (Makefile.am): Likewise. diff --git a/doc/glibc-functions/obstack_printf.texi b/doc/glibc-functions/obstack_printf.texi index 929baa629..070b79789 100644 --- a/doc/glibc-functions/obstack_printf.texi +++ b/doc/glibc-functions/obstack_printf.texi @@ -59,7 +59,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/glibc-functions/obstack_vprintf.texi b/doc/glibc-functions/obstack_vprintf.texi index d930dd477..c34efd81e 100644 --- a/doc/glibc-functions/obstack_vprintf.texi +++ b/doc/glibc-functions/obstack_vprintf.texi @@ -59,7 +59,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi index 09de039ae..ab6a91b7c 100644 --- a/doc/posix-functions/fprintf.texi +++ b/doc/posix-functions/fprintf.texi @@ -53,7 +53,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi index 1d2193961..742c8d90d 100644 --- a/doc/posix-functions/printf.texi +++ b/doc/posix-functions/printf.texi @@ -53,7 +53,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/snprintf.texi b/doc/posix-functions/snprintf.texi index 8e93c74d1..2d7379518 100644 --- a/doc/posix-functions/snprintf.texi +++ b/doc/posix-functions/snprintf.texi @@ -64,7 +64,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/sprintf.texi b/doc/posix-functions/sprintf.texi index 722beaa01..cf77bbc71 100644 --- a/doc/posix-functions/sprintf.texi +++ b/doc/posix-functions/sprintf.texi @@ -53,7 +53,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/vfprintf.texi b/doc/posix-functions/vfprintf.texi index d5d99c487..209e1b756 100644 --- a/doc/posix-functions/vfprintf.texi +++ b/doc/posix-functions/vfprintf.texi @@ -53,7 +53,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi index a311bb3ae..890bf659c 100644 --- a/doc/posix-functions/vprintf.texi +++ b/doc/posix-functions/vprintf.texi @@ -53,7 +53,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/vsnprintf.texi b/doc/posix-functions/vsnprintf.texi index 537714fe0..47e8aeaee 100644 --- a/doc/posix-functions/vsnprintf.texi +++ b/doc/posix-functions/vsnprintf.texi @@ -64,7 +64,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/doc/posix-functions/vsprintf.texi b/doc/posix-functions/vsprintf.texi index 377e0c09d..c6e629d06 100644 --- a/doc/posix-functions/vsprintf.texi +++ b/doc/posix-functions/vsprintf.texi @@ -53,7 +53,7 @@ MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, AIX 5.2, IRIX 6.5, OSF/1 5.1, Solaris 10, @item This function does not support precisions larger than 512 or 1024 in integer, floating-point and pointer output on some platforms: -mingw, BeOS. +Solaris 10/x86, mingw, BeOS. @item This function can crash in out-of-memory conditions on some platforms: MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0. diff --git a/m4/printf.m4 b/m4/printf.m4 index 0bdd795bf..9186d21dc 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 38 +# printf.m4 serial 39 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, @@ -882,8 +882,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 BeOS, precisions larger than 1044 -dnl crash the program. +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 Result is gl_cv_func_printf_precision. AC_DEFUN([gl_PRINTF_PRECISION], @@ -906,6 +907,8 @@ int main () #endif if (sprintf (buf, "%.4000d %d", 1, 33, 44) < 4000 + 3) return 1; + if (sprintf (buf, "%.4000f %d", 1.0, 33, 44) < 4000 + 5) + return 2; return 0; }]])], [gl_cv_func_printf_precision=yes], @@ -913,7 +916,8 @@ int main () [ changequote(,)dnl case "$host_os" in - # Guess no only on native Win32 and BeOS systems. + # Guess no only on Solaris, native Win32, and BeOS systems. + solaris*) gl_cv_func_printf_precision="guessing no" ;; mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; beos*) gl_cv_func_printf_precision="guessing no" ;; *) gl_cv_func_printf_precision="guessing yes" ;; @@ -1438,7 +1442,7 @@ dnl OpenBSD 3.9, 4.0 . . # # # # . # . # . # . # . dnl Cygwin 1.7.0 (2009) . . . # . . . ? . . . . . ? . . . . . . dnl Cygwin 1.5.25 (2008) . . . # # . . # . . . . . # . . . . . . dnl Cygwin 1.5.19 (2006) # . . # # # . # . # . # # # . . . . . . -dnl Solaris 10 . . # # # . . # . . . # . . . . . . . . +dnl Solaris 10 . . # # # . . # . . . # # . . . . . . . dnl Solaris 2.6 ... 9 # . # # # # . # . . . # . . . . . . . . dnl Solaris 2.5.1 # . # # # # . # . . . # . . # # # # # # dnl AIX 5.2, 7.1 . . # # # . . . . . . # . . . . . . . . diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index f55e49e47..37612f9ef 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -3032,6 +3032,19 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) } { + char result[5000]; + int retval = + my_snprintf (result, sizeof (result), "%.4000f %d", 1.0, 99); + size_t i; + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 4000; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 4000, " 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 3abe27e60..ff162aa87 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -3018,6 +3018,19 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) } { + char result[5000]; + int retval = + my_sprintf (result, "%.4000f %d", 1.0, 99); + size_t i; + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 4000; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 4000, " 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 87c58985f..dd98691ad 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -3553,6 +3553,21 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) } { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%.4000f %d", 1.0, 99); + size_t i; + ASSERT (result != NULL); + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 4000; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 4000, " 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 cd48493b8..8f71c4f97 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -3533,6 +3533,21 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) } { + char *result; + int retval = + my_asprintf (&result, "%.4000f %d", 1.0, 99); + size_t i; + ASSERT (result != NULL); + ASSERT (result[0] == '1'); + ASSERT (result[1] == '.'); + for (i = 0; i < 4000; i++) + ASSERT (result[2 + i] == '0'); + ASSERT (strcmp (result + 2 + 4000, " 99") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { char input[5000]; char *result; int retval; -- 2.11.0