bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] snprintf: port snprintf (NULL, 0, ...) to Solaris 8 and 9


From: Paul Eggert
Subject: Re: [PATCH] snprintf: port snprintf (NULL, 0, ...) to Solaris 8 and 9
Date: Thu, 23 Dec 2010 23:35:43 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7

On 12/22/2010 03:25 PM, Paul Eggert wrote:

> Thanks for the review and these are all good suggestions; I'll
> look into them.

Following up my own email -- I pushed this:

>From a80e645dd8bb8bc1bfdce5a28099995cbfd37567 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Thu, 23 Dec 2010 23:32:55 -0800
Subject: [PATCH] vsnprintf: make more consistent with snprintf; doc fixes

* doc/posix-functions/snprintf.texi (snprintf): The workaround for
the byte count return problem was promoted from the snprintf-posix
to the snprintf module.
* doc/posix-functions/vsnprintf.texi (vsnprintf): Likewise.
* m4/vsnprintf.m4 (gl_FUNC_VSNPRINTF): Also check
gl_SNPRINTF_RETVAL_C99, for consistency with gl_FUNC_SNPRINTF.
* tests/test-snprintf.c (main): Check the byte count returned.
* tests/test-vsnprintf.c (main): Likewise.
---
 ChangeLog                          |   13 +++++++++++++
 doc/posix-functions/snprintf.texi  |    6 +++---
 doc/posix-functions/vsnprintf.texi |    6 +++---
 m4/vsnprintf.m4                    |    7 ++++++-
 tests/test-snprintf.c              |    8 ++++----
 tests/test-vsnprintf.c             |    8 ++++----
 6 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 128931a..f53bcb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2010-12-23  Paul Eggert  <address@hidden>
+
+       vsnprintf: make more consistent with snprintf; doc fixes
+
+       * doc/posix-functions/snprintf.texi (snprintf): The workaround for
+       the byte count return problem was promoted from the snprintf-posix
+       to the snprintf module.
+       * doc/posix-functions/vsnprintf.texi (vsnprintf): Likewise.
+       * m4/vsnprintf.m4 (gl_FUNC_VSNPRINTF): Also check
+       gl_SNPRINTF_RETVAL_C99, for consistency with gl_FUNC_SNPRINTF.
+       * tests/test-snprintf.c (main): Check the byte count returned.
+       * tests/test-vsnprintf.c (main): Likewise.
+
 2010-12-23  Eric Blake  <address@hidden>
 
        sigpipe: relax to LGPLv2+, since it did not have any LGPLv3+ parts
diff --git a/doc/posix-functions/snprintf.texi 
b/doc/posix-functions/snprintf.texi
index 23fa5e7..5d19ccf 100644
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -12,6 +12,9 @@ Portability problems fixed by either Gnulib module 
@code{snprintf} or @code{snpr
 This function is missing on some platforms:
 IRIX 5.3, OSF/1 4.0, Solaris 2.5.1.
 @item
+This function does not return a byte count as specified in C99 on some 
platforms:
+HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw.
address@hidden
 This function overwrites memory even when a size argument of 1 is passed on 
some
 platforms:
 Linux libc5.
@@ -72,9 +75,6 @@ MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0.
 This function does not truncate the result as specified in C99 on some 
platforms:
 mingw.
 @item
-This function does not return a byte count as specified in C99 on some 
platforms:
-HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw.
address@hidden
 This function does not fully support the @samp{n} directive on some platforms:
 HP-UX 11, mingw.
 @item
diff --git a/doc/posix-functions/vsnprintf.texi 
b/doc/posix-functions/vsnprintf.texi
index 8f6d903..38266a0 100644
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -15,6 +15,9 @@ IRIX 5.3, OSF/1 4.0, Solaris 2.5.1.
 This function overwrites memory even when a size argument of 1 is passed on 
some
 platforms:
 Linux libc5.
address@hidden
+This function does not return a byte count as specified in C99 on some 
platforms:
+HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 9, mingw.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{vsnprintf-posix}:
@@ -72,9 +75,6 @@ MacOS X 10.3, FreeBSD 6.0, NetBSD 5.0.
 This function does not truncate the result as specified in C99 on some 
platforms:
 mingw.
 @item
-This function does not return a byte count as specified in C99 on some 
platforms:
-HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw.
address@hidden
 This function does not fully support the @samp{n} directive on some platforms:
 HP-UX 11, mingw.
 @item
diff --git a/m4/vsnprintf.m4 b/m4/vsnprintf.m4
index ed189c2..17109a7 100644
--- a/m4/vsnprintf.m4
+++ b/m4/vsnprintf.m4
@@ -13,7 +13,12 @@ AC_DEFUN([gl_FUNC_VSNPRINTF],
     gl_SNPRINTF_SIZE1
     case "$gl_cv_func_snprintf_size1" in
       *yes)
-        gl_cv_func_vsnprintf_usable=yes
+        gl_SNPRINTF_RETVAL_C99
+        case "$gl_cv_func_snprintf_retval_c99" in
+          *yes)
+            gl_cv_func_vsnprintf_usable=yes
+            ;;
+        esac
         ;;
     esac
   fi
diff --git a/tests/test-snprintf.c b/tests/test-snprintf.c
index 62a411b..e408d48 100644
--- a/tests/test-snprintf.c
+++ b/tests/test-snprintf.c
@@ -34,15 +34,16 @@ main (int argc, char *argv[])
   int size;
   int retval;
 
+  retval = snprintf (NULL, 0, "%d", 12345);
+  ASSERT (retval == 5);
+
   for (size = 0; size <= 8; size++)
     {
       memcpy (buf, "DEADBEEF", 8);
       retval = snprintf (buf, size, "%d", 12345);
+      ASSERT (retval == 5);
       if (size < 6)
         {
-#if CHECK_SNPRINTF_POSIX
-          ASSERT (retval < 0 || retval >= size);
-#endif
           if (size > 0)
             {
               ASSERT (memcmp (buf, "12345", size - 1) == 0);
@@ -55,7 +56,6 @@ main (int argc, char *argv[])
         }
       else
         {
-          ASSERT (retval == 5);
           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
         }
     }
diff --git a/tests/test-vsnprintf.c b/tests/test-vsnprintf.c
index 1bfa554..7234da3 100644
--- a/tests/test-vsnprintf.c
+++ b/tests/test-vsnprintf.c
@@ -47,15 +47,16 @@ main (int argc, char *argv[])
   int size;
   int retval;
 
+  retval = my_snprintf (NULL, 0, "%d", 12345);
+  ASSERT (retval == 5);
+
   for (size = 0; size <= 8; size++)
     {
       memcpy (buf, "DEADBEEF", 8);
       retval = my_snprintf (buf, size, "%d", 12345);
+      ASSERT (retval == 5);
       if (size < 6)
         {
-#if CHECK_VSNPRINTF_POSIX
-          ASSERT (retval < 0 || retval >= size);
-#endif
           if (size > 0)
             {
               ASSERT (memcmp (buf, "12345", size - 1) == 0);
@@ -68,7 +69,6 @@ main (int argc, char *argv[])
         }
       else
         {
-          ASSERT (retval == 5);
           ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
         }
     }
-- 
1.7.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]