From 196885ad9339f95eca17ab4d97d4ef51d3366fb1 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Fri, 30 Sep 2016 10:38:31 +0700 Subject: [PATCH] reformatting: cJSON_AddItemToObject --- cJSON.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cJSON.c b/cJSON.c index 753e136..8d20c8d 100644 --- a/cJSON.c +++ b/cJSON.c @@ -1666,7 +1666,23 @@ void cJSON_AddItemToArray(cJSON *array, cJSON *item) } } -void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);} +void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + if (!item) + { + return; + } + + /* free old key and set new one */ + if (item->string) + { + cJSON_free(item->string); + } + item->string = cJSON_strdup(string); + + cJSON_AddItemToArray(object,item); +} + void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (!(item->type&cJSON_StringIsConst) && item->string) cJSON_free(item->string);item->string=(char*)string;item->type|=cJSON_StringIsConst;cJSON_AddItemToArray(object,item);} void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));} void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}