]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Update from gnulib.
authorBruno Haible <bruno@clisp.org>
Fri, 9 Nov 2007 12:09:18 +0000 (12:09 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:32 +0000 (12:15 +0200)
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/vasnprintf.c
gettext-runtime/libasprintf/ChangeLog
gettext-runtime/libasprintf/vasnprintf.c

index 7c3f75a3faa24a604d2ce533f5225a4ec782d83c..8f18d00e8f902a2dc095957112bbdfcae89d36b7 100644 (file)
@@ -1,3 +1,13 @@
+2007-11-09  Bruno Haible  <bruno@clisp.org>
+
+       * vasnprintf.c (VASNPRINTF): Ensure that we never call snprintf with a
+       size argument < 2.
+
+2007-11-09  Bruno Haible  <bruno@clisp.org>
+
+       * vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf buffer.
+       Fixes an inefficiency introduced on 2007-11-03.
+
 2007-11-07  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.17 released.
index 4a8e7f05a6018309cfadc8ae0a00e42658992176..a5fddfadef67064c103113c56515f5c1a6d6bb0b 100644 (file)
@@ -4047,9 +4047,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
 
@@ -4295,13 +4299,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                          goto overflow;
                        else
                          {
-                           /* Need at least count * sizeof (TCHAR_T) bytes.
-                              But allocate proportionally, to avoid looping
+                           /* Need at least (count + 1) * sizeof (TCHAR_T)
+                              bytes.  (The +1 is for the trailing NUL.)
+                              But ask for (count + 2) * sizeof (TCHAR_T)
+                              bytes, so that in the next round, we likely get
+                                maxlen > (unsigned int) count + 1
+                              and so we don't get here again.
+                              And allocate proportionally, to avoid looping
                               eternally if snprintf() reports a too small
                               count.  */
                            size_t n =
                              xmax (xsum (length,
-                                         (count + TCHARS_PER_DCHAR - 1)
+                                         ((unsigned int) count + 2
+                                          + TCHARS_PER_DCHAR - 1)
                                          / TCHARS_PER_DCHAR),
                                    xtimes (allocated, 2));
 
index e154abcae0b7be06103146da8ab17ec62310f987..afb4758ea812e42055da19df76bc3f0b3a396938 100644 (file)
@@ -1,3 +1,13 @@
+2007-11-09  Bruno Haible  <bruno@clisp.org>
+
+       * vasnprintf.c (VASNPRINTF): Ensure that we never call snprintf with a
+       size argument < 2.
+
+2007-11-09  Bruno Haible  <bruno@clisp.org>
+
+       * vasnprintf.c (VASNPRINTF): Increase reallocation of snprintf buffer.
+       Fixes an inefficiency introduced on 2007-11-03.
+
 2007-11-07  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.17 released.
index 4a8e7f05a6018309cfadc8ae0a00e42658992176..a5fddfadef67064c103113c56515f5c1a6d6bb0b 100644 (file)
@@ -4047,9 +4047,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
 
@@ -4295,13 +4299,19 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                          goto overflow;
                        else
                          {
-                           /* Need at least count * sizeof (TCHAR_T) bytes.
-                              But allocate proportionally, to avoid looping
+                           /* Need at least (count + 1) * sizeof (TCHAR_T)
+                              bytes.  (The +1 is for the trailing NUL.)
+                              But ask for (count + 2) * sizeof (TCHAR_T)
+                              bytes, so that in the next round, we likely get
+                                maxlen > (unsigned int) count + 1
+                              and so we don't get here again.
+                              And allocate proportionally, to avoid looping
                               eternally if snprintf() reports a too small
                               count.  */
                            size_t n =
                              xmax (xsum (length,
-                                         (count + TCHARS_PER_DCHAR - 1)
+                                         ((unsigned int) count + 2
+                                          + TCHARS_PER_DCHAR - 1)
                                          / TCHARS_PER_DCHAR),
                                    xtimes (allocated, 2));