| 1901 | |
| 1902 | |
| 1903 | 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) |
| 1904 | { |
| 1905 | char *new_key = NULL; |
| 1906 | int new_type = cJSON_Invalid; |
| 1907 | |
| 1908 | if ((object == NULL) || (string == NULL) || (item == NULL)) |
| 1909 | { |
| 1910 | return false; |
| 1911 | } |
| 1912 | |
| 1913 | if (constant_key) |
| 1914 | { |
| 1915 | new_key = (char*)cast_away_const(string); |
| 1916 | new_type = item->type | cJSON_StringIsConst; |
| 1917 | } |
| 1918 | else |
| 1919 | { |
| 1920 | new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); |
| 1921 | if (new_key == NULL) |
| 1922 | { |
| 1923 | return false; |
| 1924 | } |
| 1925 | |
| 1926 | new_type = item->type & ~cJSON_StringIsConst; |
| 1927 | } |
| 1928 | |
| 1929 | if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) |
| 1930 | { |
| 1931 | hooks->deallocate(item->string); |
| 1932 | } |
| 1933 | |
| 1934 | item->string = new_key; |
| 1935 | item->type = new_type; |
| 1936 | |
| 1937 | return add_item_to_array(object, item); |
| 1938 | } |
| 1939 | |
| 1940 | CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) |
| 1941 | { |
no test coverage detected