diff options
author | Nicolas Williams <nico@cryptonector.com> | 2014-06-02 00:56:01 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2014-06-02 00:56:01 -0500 |
commit | 5fb82d1018681f41230a3ff6dc412ddad511e821 (patch) | |
tree | f6c7a40a73a4669197f613b972426de79093261b | |
parent | f9d1b94496a66dacec040fb2710eb9a740ce137a (diff) |
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.
-rw-r--r-- | jv.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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); } } } |