Check if we have enough place to add quotes
@@ -362,6 +362,8 @@ int json_emit_double(char *buf, int buf_len, double value) {
int json_emit_quoted_str(char *buf, int buf_len, const char *str) {
int i = 0, j = 0, ch;
+ if (buf_len <= 1) return 0;
+
#define EMIT(x) do { if (j < buf_len) buf[j++] = x; } while (0)
EMIT('"');