# HG changeset patch # User Matti Hamalainen # Date 1308816563 -10800 # Node ID 3986b139bbbd98eed3e0c46cf8fe0a9dffe7f0f5 # Parent 760788e216993bd3de87f72c5743e9e3b44be1eb Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :( diff -r 760788e21699 -r 3986b139bbbd th_string.c --- a/th_string.c Thu Jun 23 11:08:59 2011 +0300 +++ b/th_string.c Thu Jun 23 11:09:23 2011 +0300 @@ -58,21 +58,27 @@ */ char * th_strdup_vprintf(const char *fmt, va_list args) { - int size = 100; + int size = 64; char *buf, *nbuf = NULL; if ((buf = th_malloc(size)) == NULL) return NULL; + fprintf(stderr, "th_strdup_vprintf(\"%s\", ...):\n", fmt); while (1) { - int n = vsnprintf(buf, size, fmt, args); + int n; + va_list ap; + va_copy(ap, args); + n = vsnprintf(buf, size, fmt, ap); + va_end(ap); + if (n > -1 && n < size) return buf; if (n > -1) size = n + 1; else size *= 2; - + if ((nbuf = th_realloc(nbuf, size)) == NULL) { th_free(buf); return NULL;