]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Tweak xstrcat function.
authorBruno Haible <bruno@clisp.org>
Tue, 9 May 2006 17:29:04 +0000 (17:29 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:15 +0000 (12:13 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/lib/xvasprintf.c

index 02f32ea7a250a96e49a8922b904bd3d997b83b20..7278d3233db184903a95a5705e36617746201fce 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-09  Bruno Haible  <bruno@clisp.org>
+
+       * xvasprintf.c (xstrcat): Handle overflow. Suggested by Paul Eggert.
+       Optimize away a va_copy call. Suggested by Eric Blake. Add missing
+       va_end call.
+
 2006-05-06  Charles Wilson  <cygwin@cwilson.fastmail.fm>
 
        * progreloc.c (maybe_executable) [CYGWIN]: Use the access() function.
index 4e95375dc3e75c4a3312613713f254e4d3dc495d..d68a50d83c61dc79cfe6db4c2248265d0bba598a 100644 (file)
@@ -54,10 +54,12 @@ xstrcat (size_t argcount, va_list args)
       const char *next = va_arg (ap, const char *);
       totalsize = xsum (totalsize, strlen (next));
     }
+  va_end (ap);
 
-  /* Don't return a string longer than INT_MAX, for consistency with
+  /* Test for overflow in the summing pass above or in (totalsize + 1) below.
+     Also, don't return a string longer than INT_MAX, for consistency with
      vasprintf().  */
-  if (totalsize > INT_MAX)
+  if (totalsize == SIZE_MAX || totalsize > INT_MAX)
     {
       errno = EOVERFLOW;
       return NULL;
@@ -66,10 +68,9 @@ xstrcat (size_t argcount, va_list args)
   /* Allocate and fill the result string.  */
   result = (char *) xmalloc (totalsize + 1);
   p = result;
-  va_copy (ap, args);
   for (i = argcount; i > 0; i--)
     {
-      const char *next = va_arg (ap, const char *);
+      const char *next = va_arg (args, const char *);
       size_t len = strlen (next);
       memcpy (p, next, len);
       p += len;