From f33fa95f3d4411bc8b9624d5ae8ecc9b22d1ff1c Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 9 Jan 2018 20:49:03 +0100 Subject: [PATCH] print: Fix default buffer size in printbuffer Thanks @liuyunbin for reporting this in #230 --- cJSON.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 2f747ea..71ac65c 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1087,13 +1087,15 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) { + static const size_t default_buffer_size = 256; printbuffer buffer[1]; unsigned char *printed = NULL; memset(buffer, 0, sizeof(buffer)); /* create buffer */ - buffer->buffer = (unsigned char*) hooks->allocate(256); + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; buffer->format = format; buffer->hooks = *hooks; if (buffer->buffer == NULL)