From 5fba87291f6a5c22c204494d6d2664675d13e30f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 26 Feb 2009 13:38:03 +0100 Subject: [PATCH] Work around *printf bug with %g directive and 0.0 on HP-UX 10.20. --- ChangeLog | 6 ++++++ m4/printf.m4 | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9919aa0ba..3aa297e1a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2009-02-26 Bruno Haible + Work around *printf bug with %g directive and 0.0 on HP-UX 10.20. + * m4/printf.m4 (gl_PRINTF_INFINITE): Also test for %g output of -0.0. + Reported by Gary V. Vaughan . + +2009-02-26 Bruno Haible + Fix *printf behaviour regarding the %ls directive. * m4/printf.m4 (gl_PRINTF_DIRECTIVE_LS): New macro. * lib/vasnprintf.c (local_wcslen, VASNPRINTF): Handle diff --git a/m4/printf.m4 b/m4/printf.m4 index 383374bb0..f3e201b52 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 29 +# printf.m4 serial 30 dnl Copyright (C) 2003, 2007-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -125,7 +125,8 @@ changequote([,])dnl ]) dnl Test whether the *printf family of functions supports infinite and NaN -dnl 'double' arguments in the %f, %e, %g directives. (ISO C99, POSIX:2001) +dnl 'double' arguments and negative zero arguments in the %f, %e, %g +dnl directives. (ISO C99, POSIX:2001) dnl Result is gl_cv_func_printf_infinite. AC_DEFUN([gl_PRINTF_INFINITE], @@ -156,6 +157,13 @@ strisnan (const char *string, size_t start_index, size_t end_index) } return 0; } +static int +have_minus_zero () +{ + static double plus_zero = 0.0; + double minus_zero = - plus_zero; + return memcmp (&plus_zero, &minus_zero, sizeof (double)) != 0; +} static char buf[10000]; static double zero = 0.0; int main () @@ -187,6 +195,11 @@ int main () if (sprintf (buf, "%g", zero / zero) < 0 || !strisnan (buf, 0, strlen (buf))) return 1; + /* This test fails on HP-UX 10.20. */ + if (have_minus_zero ()) + if (sprintf (buf, "%g", - zero) < 0 + || strcmp (buf, "-0") != 0) + return 1; return 0; }], [gl_cv_func_printf_infinite=yes], [gl_cv_func_printf_infinite=no], [ @@ -1357,7 +1370,7 @@ dnl AIX 5.2 . . # # # . . . . . . # . . . dnl AIX 4.3.2, 5.1 # . # # # # . . . . . # . . . . . . . . dnl HP-UX 11.31 . . . . # . . . . . . # . . . . # # . . dnl HP-UX 11.{00,11,23} # . . . # # . . . . . # . . . . # # . # -dnl HP-UX 10.20 # . . . # # . ? . . # # . . . . # # ? # +dnl HP-UX 10.20 # . # . # # . ? . . # # . . . . # # ? # dnl IRIX 6.5 # . # # # # . # . . . # . . . . # . . . dnl OSF/1 5.1 # . # # # # . . . . . # . . . . # . . # dnl OSF/1 4.0d # . # # # # . . . . . # . . # # # # # # -- 2.11.0