+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.
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;
/* 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;