| 2065 | |
| 2066 | |
| 2067 | 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) |
| 2068 | { |
| 2069 | char *new_key = NULL; |
| 2070 | int new_type = cJSON_Invalid; |
| 2071 | |
| 2072 | if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) |
| 2073 | { |
| 2074 | return false; |
| 2075 | } |
| 2076 | |
| 2077 | if (constant_key) |
| 2078 | { |
| 2079 | new_key = (char*)cast_away_const(string); |
| 2080 | new_type = item->type | cJSON_StringIsConst; |
| 2081 | } |
| 2082 | else |
| 2083 | { |
| 2084 | new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); |
| 2085 | if (new_key == NULL) |
| 2086 | { |
| 2087 | return false; |
| 2088 | } |
| 2089 | |
| 2090 | new_type = item->type & ~cJSON_StringIsConst; |
| 2091 | } |
| 2092 | |
| 2093 | if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) |
| 2094 | { |
| 2095 | hooks->deallocate(item->string); |
| 2096 | } |
| 2097 | |
| 2098 | item->string = new_key; |
| 2099 | item->type = new_type; |
| 2100 | |
| 2101 | return add_item_to_array(object, item); |
| 2102 | } |
| 2103 | |
| 2104 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) |
| 2105 | { |
no test coverage detected
searching dependent graphs…