Document and work around a BeOS snprintf() bug.
authorBruno Haible <bruno@clisp.org>
Fri, 9 Nov 2007 11:59:46 +0000 (12:59 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 9 Nov 2007 11:59:46 +0000 (12:59 +0100)
ChangeLog
doc/functions/snprintf.texi
doc/functions/vsnprintf.texi
lib/vasnprintf.c

index 727651c..09587c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2007-11-09  Bruno Haible  <bruno@clisp.org>
 
+       * doc/functions/snprintf.texi: Mention BeOS deficiency.
+       * doc/functions/vsnprintf.texi: Likewise.
+       * lib/vasnprintf.c (VASNPRINTF): Ensure that we never call snprintf
+       with a size argument < 2.
+
+2007-11-09  Bruno Haible  <bruno@clisp.org>
+
        * lib/vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf
        buffer. Fixes an inefficiency introduced on 2007-11-03.
 
index 7e5f2f8..43ca802 100644 (file)
@@ -61,6 +61,10 @@ HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw.
 This function does not fully support the @samp{n} directive on some platforms:
 HP-UX 11, mingw.
 @item
+This function overwrites memory when a size = 1 argument is passed on some
+platforms:
+BeOS.
+@item
 This function overwrites memory even when a zero size argument is passed on some
 platforms:
 OSF/1 5.1.
index 13c009c..645ae70 100644 (file)
@@ -61,6 +61,10 @@ HP-UX 11, IRIX 6.5, OSF/1 5.1, mingw.
 This function does not fully support the @samp{n} directive on some platforms:
 HP-UX 11, mingw.
 @item
+This function overwrites memory when a size = 1 argument is passed on some
+platforms:
+BeOS.
+@item
 This function overwrites memory even when a zero size argument is passed on some
 platforms:
 HP-UX 11, OSF/1 5.1.
index ccc531b..d6b012a 100644 (file)
@@ -4046,9 +4046,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   sizeof (TCHAR_T) divides sizeof (DCHAR_T) and
                   alignof (TCHAR_T) <= alignof (DCHAR_T).  */
 # define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T))
+               /* Ensure that maxlen below will be >= 2.  Needed on BeOS,
+                  where an snprintf() with maxlen==1 acts like sprintf().  */
+               ENSURE_ALLOCATION (xsum (length,
+                                        (2 + TCHARS_PER_DCHAR - 1)
+                                        / TCHARS_PER_DCHAR));
                /* Prepare checking whether snprintf returns the count
                   via %n.  */
-               ENSURE_ALLOCATION (xsum (length, 1));
                *(TCHAR_T *) (result + length) = '\0';
 #endif