|
@@ -82,7 +82,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) {
|
|
}
|
|
}
|
|
|
|
|
|
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
|
|
/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */
|
|
-#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 3)
|
|
|
|
|
|
+#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 4)
|
|
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
|
#error cJSON.h and cJSON.c have different versions. Make sure that both have the same.
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -1895,33 +1895,38 @@ static void* cast_away_const(const void* string)
|
|
|
|
|
|
static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key)
|
|
static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key)
|
|
{
|
|
{
|
|
|
|
+ char *new_key = NULL;
|
|
|
|
+ int new_type = cJSON_Invalid;
|
|
|
|
+
|
|
if ((object == NULL) || (string == NULL) || (item == NULL))
|
|
if ((object == NULL) || (string == NULL) || (item == NULL))
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
|
|
|
|
- {
|
|
|
|
- hooks->deallocate(item->string);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (constant_key)
|
|
if (constant_key)
|
|
{
|
|
{
|
|
- item->string = (char*)cast_away_const(string);
|
|
|
|
- item->type |= cJSON_StringIsConst;
|
|
|
|
|
|
+ new_key = (char*)cast_away_const(string);
|
|
|
|
+ new_type = item->type | cJSON_StringIsConst;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- char *key = (char*)cJSON_strdup((const unsigned char*)string, hooks);
|
|
|
|
- if (key == NULL)
|
|
|
|
|
|
+ new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks);
|
|
|
|
+ if (new_key == NULL)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- item->string = key;
|
|
|
|
- item->type &= ~cJSON_StringIsConst;
|
|
|
|
|
|
+ new_type = item->type & ~cJSON_StringIsConst;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
|
|
|
|
+ {
|
|
|
|
+ hooks->deallocate(item->string);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ item->string = new_key;
|
|
|
|
+ item->type = new_type;
|
|
|
|
+
|
|
return add_item_to_array(object, item);
|
|
return add_item_to_array(object, item);
|
|
}
|
|
}
|
|
|
|
|