Browse Source

print: Fix default buffer size in printbuffer

Thanks @liuyunbin for reporting this in #230
Max Bruckner 7 years ago
parent
commit
f33fa95f3d
1 changed files with 3 additions and 1 deletions
  1. 3 1
      cJSON.c

+ 3 - 1
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 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];
     printbuffer buffer[1];
     unsigned char *printed = NULL;
     unsigned char *printed = NULL;
 
 
     memset(buffer, 0, sizeof(buffer));
     memset(buffer, 0, sizeof(buffer));
 
 
     /* create 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->format = format;
     buffer->hooks = *hooks;
     buffer->hooks = *hooks;
     if (buffer->buffer == NULL)
     if (buffer->buffer == NULL)