From 3c4d309f621edc21d2ecbc25477b18a7a0fbe9ae Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Sun, 19 Feb 2017 04:20:21 +0100 Subject: [PATCH] ensure: Don't accept empty printbuffers anymore --- cJSON.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cJSON.c b/cJSON.c index a5cd84b..598f9cf 100644 --- a/cJSON.c +++ b/cJSON.c @@ -241,9 +241,9 @@ static unsigned char* ensure(printbuffer *p, size_t needed) unsigned char *newbuffer = NULL; size_t newsize = 0; - if (p == NULL) + if ((p == NULL) || (p->buffer == NULL)) { - return (unsigned char*)cJSON_malloc(needed); + return NULL; } if (needed > INT_MAX) @@ -252,10 +252,6 @@ static unsigned char* ensure(printbuffer *p, size_t needed) return NULL; } - if (p->buffer == NULL) - { - return NULL; - } needed += p->offset; if (needed <= p->length) {