From cf862d0fed7f9407e4b046d78d3d8050d2080d12 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Wed, 15 Feb 2017 21:46:24 +0100 Subject: [PATCH] implement AddItemToObject using AddItemToObjectCS --- cJSON.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/cJSON.c b/cJSON.c index 0f861c5..cf534ba 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1775,19 +1775,10 @@ void cJSON_AddItemToArray(cJSON *array, cJSON *item) void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { - if (!item) - { - return; - } - - /* free old key and set new one */ - if (!(item->type & cJSON_StringIsConst) && item->string) - { - cJSON_free(item->string); - } - item->string = (char*)cJSON_strdup((const unsigned char*)string); - - cJSON_AddItemToArray(object,item); + /* call cJSON_AddItemToObjectCS for code reuse */ + cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string), item); + /* remove cJSON_StringIsConst flag */ + item->type &= ~cJSON_StringIsConst; } /* Add an item to an object with constant string as key */