From 5fb82d1018681f41230a3ff6dc412ddad511e821 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Mon, 2 Jun 2014 00:56:01 -0500 Subject: Fix tests failures on Windows And Solaris 8 and 9 too, no doubt. The problem was that non-standard vsnprintf()s that return -1 when the buffer is too small were not properly supported. --- jv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jv.c b/jv.c index e969b120..24971af6 100644 --- a/jv.c +++ b/jv.c @@ -793,13 +793,17 @@ jv jv_string_vfmt(const char* fmt, va_list ap) { va_copy(ap2, ap); int n = vsnprintf(buf, size, fmt, ap2); va_end(ap2); - if (n < size) { + /* + * NOTE: here we support old vsnprintf()s that return -1 because the + * buffer is too small. + */ + if (n >= 0 && n < size) { jv ret = jv_string_sized(buf, n); jv_mem_free(buf); return ret; } else { jv_mem_free(buf); - size = n * 2; + size = (n > 0) ? /* standard */ (n * 2) : /* not standard */ (size * 2); } } } -- cgit v1.2.3