Properly handle the case where vsnprintf returns -1.

This commit is contained in:
Alexandre Julliard 2005-09-12 20:31:33 +00:00
parent d559fbd803
commit 3a503499aa
1 changed files with 5 additions and 5 deletions

View File

@ -79,18 +79,18 @@ char* strmake(const char* fmt, ...)
{ {
int n; int n;
size_t size = 100; size_t size = 100;
char* p;
va_list ap; va_list ap;
p = xmalloc (size);
while (1) while (1)
{ {
char *p = xmalloc (size);
va_start(ap, fmt); va_start(ap, fmt);
n = vsnprintf (p, size, fmt, ap); n = vsnprintf (p, size, fmt, ap);
va_end(ap); va_end(ap);
if (n > -1 && (size_t)n < size) return p; if (n == -1) size *= 2;
size = min( size*2, (size_t)n+1 ); else if ((size_t)n >= size) size = n + 1;
p = xrealloc (p, size); else return p;
free(p);
} }
} }