| 2027 | |
| 2028 | |
| 2029 | 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) |
| 2030 | { |
| 2031 | char *new_key = NULL; |
| 2032 | int new_type = cJSON_Invalid; |
| 2033 | |
| 2034 | if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) |
| 2035 | { |
| 2036 | return false; |
| 2037 | } |
| 2038 | |
| 2039 | if (constant_key) |
| 2040 | { |
| 2041 | new_key = (char*)cast_away_const(string); |
| 2042 | new_type = item->type | cJSON_StringIsConst; |
| 2043 | } |
| 2044 | else |
| 2045 | { |
| 2046 | new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); |
| 2047 | if (new_key == NULL) |
| 2048 | { |
| 2049 | return false; |
| 2050 | } |
| 2051 | |
| 2052 | new_type = item->type & ~cJSON_StringIsConst; |
| 2053 | } |
| 2054 | |
| 2055 | if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) |
| 2056 | { |
| 2057 | hooks->deallocate(item->string); |
| 2058 | } |
| 2059 | |
| 2060 | item->string = new_key; |
| 2061 | item->type = new_type; |
| 2062 | |
| 2063 | return add_item_to_array(object, item); |
| 2064 | } |
| 2065 | |
| 2066 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) |
| 2067 | { |
no test coverage detected