snprintf: port snprintf (NULL, 0, ...) to Solaris 8 and 9
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 21 Dec 2010 09:15:32 +0000 (01:15 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 21 Dec 2010 09:16:06 +0000 (01:16 -0800)
This fixes a problem observed with the latest coreutils snapshot
that caused a test to fail on Solaris 8.  src/csplit.c's call
snprintf (NULL, 0, format, UINT_MAX) returns -1 on Solaris 9 and
earlier, instead of returning the number of bytes that would have
been generated; this causes csplit to incorrectly report memory
exhaustion.
* m4/printf.m4 (gl_SNPRINTF_RETVAL_C99): Also check for
snprintf (NULL, 0, ...) and (for good measure) snprintf (buf, 0, ...).
Guess that it doesn't work on Solaris 2.6 through 9.  Adjust
comments to match.
(gl_PRINTF_SIZES_C99, gl_PRINTF_DIRECTIVE_F, gl_SNPRINTF_RETVAL_C99):
Fix typo in matching older versions of Solaris: "solaris2.10"
is matched by the shell pattern "solaris2.[0-9]*".  This matters
only for guessing while cross-compiling.
* m4/snprintf.m4 (gl_FUNC_SNPRINTF): Also check gl_SNPRINTF_RETVAL_C99.

ChangeLog
m4/printf.m4
m4/snprintf.m4

index 58c2782..0e6d4fa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2010-12-21  Paul Eggert  <eggert@cs.ucla.edu>
+
+       snprintf: port snprintf (NULL, 0, ...) to Solaris 8 and 9
+       This fixes a problem observed with the latest coreutils snapshot
+       that caused a test to fail on Solaris 8.  src/csplit.c's call
+       snprintf (NULL, 0, format, UINT_MAX) returns -1 on Solaris 9 and
+       earlier, instead of returning the number of bytes that would have
+       been generated; this causes csplit to incorrectly report memory
+       exhaustion.
+       * m4/printf.m4 (gl_SNPRINTF_RETVAL_C99): Also check for
+       snprintf (NULL, 0, ...) and (for good measure) snprintf (buf, 0, ...).
+       Guess that it doesn't work on Solaris 2.6 through 9.  Adjust
+       comments to match.
+       (gl_PRINTF_SIZES_C99, gl_PRINTF_DIRECTIVE_F, gl_SNPRINTF_RETVAL_C99):
+       Fix typo in matching older versions of Solaris: "solaris2.10"
+       is matched by the shell pattern "solaris2.[0-9]*".  This matters
+       only for guessing while cross-compiling.
+       * m4/snprintf.m4 (gl_FUNC_SNPRINTF): Also check gl_SNPRINTF_RETVAL_C99.
+
 2010-12-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        ftoastr: fix comment again
index 6d1cbfe..f54b8a9 100644 (file)
@@ -71,8 +71,8 @@ changequote(,)dnl
                                  gl_cv_func_printf_sizes_c99="guessing no";;
            openbsd*)             gl_cv_func_printf_sizes_c99="guessing yes";;
                                  # Guess yes on Solaris >= 2.10.
-           solaris2.[0-9]*)      gl_cv_func_printf_sizes_c99="guessing no";;
-           solaris*)             gl_cv_func_printf_sizes_c99="guessing yes";;
+           solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
+           solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
                                  # Guess yes on NetBSD >= 3.
            netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*)
                                  gl_cv_func_printf_sizes_c99="guessing no";;
@@ -591,8 +591,8 @@ changequote(,)dnl
            darwin[1-6].*)        gl_cv_func_printf_directive_f="guessing no";;
            darwin*)              gl_cv_func_printf_directive_f="guessing yes";;
                                  # Guess yes on Solaris >= 2.10.
-           solaris2.[0-9]*)      gl_cv_func_printf_directive_f="guessing no";;
-           solaris*)             gl_cv_func_printf_directive_f="guessing yes";;
+           solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
+           solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
                                  # If we don't know, assume the worst.
            *)                    gl_cv_func_printf_directive_f="guessing no";;
          esac
@@ -1161,6 +1161,10 @@ int main ()
   strcpy (buf, "ABCDEF");
   if (snprintf (buf, 3, "%d %d", 4567, 89) != 7)
     return 1;
+  if (snprintf (buf, 0, "%d %d", 4567, 89) != 7)
+    return 2;
+  if (snprintf (NULL, 0, "%d %d", 4567, 89) != 7)
+    return 3;
   return 0;
 }]])],
         [gl_cv_func_snprintf_retval_c99=yes],
@@ -1180,9 +1184,9 @@ changequote(,)dnl
            openbsd[1-2].* | openbsd3.[0-8] | openbsd3.[0-8].*)
                                  gl_cv_func_snprintf_retval_c99="guessing no";;
            openbsd*)             gl_cv_func_snprintf_retval_c99="guessing yes";;
-                                 # Guess yes on Solaris >= 2.6.
-           solaris2.[0-5]*)      gl_cv_func_snprintf_retval_c99="guessing no";;
-           solaris*)             gl_cv_func_snprintf_retval_c99="guessing yes";;
+                                 # Guess yes on Solaris >= 2.10.
+           solaris2.[1-9][0-9]*) gl_cv_func_printf_sizes_c99="guessing yes";;
+           solaris*)             gl_cv_func_printf_sizes_c99="guessing no";;
                                  # Guess yes on AIX >= 4.
            aix[1-3]*)            gl_cv_func_snprintf_retval_c99="guessing no";;
            aix*)                 gl_cv_func_snprintf_retval_c99="guessing yes";;
@@ -1452,10 +1456,10 @@ 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                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  .  .  .  .
+dnl   AIX 4.3.2, 5.1                 #  .  #  #  #  #  .  .  .  .  .  #  .  .  .  .  #  .  .  .
 dnl   HP-UX 11.31                    .  .  .  .  #  .  .  .  .  .  .  #  .  .  .  .  #  #  .  .
 dnl   HP-UX 11.{00,11,23}            #  .  .  .  #  #  .  .  .  .  .  #  .  .  .  .  #  #  .  #
 dnl   HP-UX 10.20                    #  .  #  .  #  #  .  ?  .  .  #  #  .  .  .  .  #  #  ?  #
@@ -1465,6 +1469,6 @@ dnl   OSF/1 4.0d                     #  .  #  #  #  #  .  .  .  .  .  #  .  .  #
 dnl   NetBSD 5.0                     .  .  .  #  #  .  .  .  .  .  .  #  .  #  .  .  .  .  .  .
 dnl   NetBSD 4.0                     .  ?  ?  ?  ?  ?  .  ?  .  ?  ?  ?  ?  ?  .  .  .  ?  ?  ?
 dnl   NetBSD 3.0                     .  .  .  .  #  #  .  ?  #  #  ?  #  .  #  .  .  .  .  .  .
-dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  .  .  .  .  .  .
-dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  .  .  .  .  .  .
+dnl   Haiku                          .  .  .  #  #  #  .  #  .  .  .  .  .  ?  .  .  ?  .  .  .
+dnl   BeOS                           #  #  .  #  #  #  .  ?  #  .  ?  .  #  ?  .  .  ?  .  .  .
 dnl   mingw                          #  #  #  #  #  #  .  .  #  #  .  #  #  ?  .  #  #  #  .  .
index 522b107..80ac6fd 100644 (file)
@@ -13,7 +13,12 @@ AC_DEFUN([gl_FUNC_SNPRINTF],
     gl_SNPRINTF_SIZE1
     case "$gl_cv_func_snprintf_size1" in
       *yes)
-        gl_cv_func_snprintf_usable=yes
+        gl_SNPRINTF_RETVAL_C99
+        case "$gl_cv_func_snprintf_retval_c99" in
+          *yes)
+            gl_cv_func_snprintf_usable=yes
+            ;;
+        esac
         ;;
     esac
   fi