summaryrefslogtreecommitdiffstats
path: root/jv.c
diff options
context:
space:
mode:
Diffstat (limited to 'jv.c')
-rw-r--r--jv.c8
1 files 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);
}
}
}