From 28d4410f42a64515290ce94688bcbbb9b2337c1f Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 9 Jan 2018 20:53:33 +0100 Subject: [PATCH] print: fix: realloc was allocating too much memory Thanks @liuyunbin for reporting this in #230 --- cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 71ac65c..9b6ef33 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1113,7 +1113,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i /* check if reallocate is available */ if (hooks->reallocate != NULL) { - printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->length); + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); buffer->buffer = NULL; if (printed == NULL) { goto fail;