From cdc35ebf88c5d440b8f63e9a69412c22c0abb6fa Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Tue, 27 Jun 2017 21:34:42 +0200 Subject: [PATCH] handle null pointers: cJSON_AddItemToObject --- cJSON.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cJSON.c b/cJSON.c index 4c12f20..16acd42 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1790,6 +1790,11 @@ CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { + if (item == NULL) + { + return; + } + /* call cJSON_AddItemToObjectCS for code reuse */ cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string, &global_hooks), item); /* remove cJSON_StringIsConst flag */