| 2005 | |
| 2006 | |
| 2007 | 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) |
| 2008 | { |
| 2009 | char *new_key = NULL; |
| 2010 | int new_type = cJSON_Invalid; |
| 2011 | |
| 2012 | if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item)) |
| 2013 | { |
| 2014 | return false; |
| 2015 | } |
| 2016 | |
| 2017 | if (constant_key) |
| 2018 | { |
| 2019 | new_key = (char*)cast_away_const(string); |
| 2020 | new_type = item->type | cJSON_StringIsConst; |
| 2021 | } |
| 2022 | else |
| 2023 | { |
| 2024 | new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); |
| 2025 | if (new_key == NULL) |
| 2026 | { |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
| 2030 | new_type = item->type & ~cJSON_StringIsConst; |
| 2031 | } |
| 2032 | |
| 2033 | if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) |
| 2034 | { |
| 2035 | hooks->deallocate(item->string); |
| 2036 | } |
| 2037 | |
| 2038 | item->string = new_key; |
| 2039 | item->type = new_type; |
| 2040 | |
| 2041 | return add_item_to_array(object, item); |
| 2042 | } |
| 2043 | |
| 2044 | CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) |
| 2045 | { |
no test coverage detected