From 331c18d09a7bd2fcda91fcdb025178ec8d3a2720 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sat, 18 Feb 2017 11:58:24 +0100 Subject: [PATCH] ensure: only memcopy what's necessary We don't need to copy the entire printbuffer, only the part that is used. --- cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 4b5005a..89943b5 100644 --- a/cJSON.c +++ b/cJSON.c @@ -300,7 +300,7 @@ static unsigned char* ensure(printbuffer *p, size_t needed) } if (newbuffer) { - memcpy(newbuffer, p->buffer, p->length); + memcpy(newbuffer, p->buffer, p->offset + 1); } cJSON_free(p->buffer); }