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.
This commit is contained in:
1 parent
f9d1b94496
commit
5fb82d1018
1 file changed
+6
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user