Replace array/object items with new ones. */
| 2279 | |
| 2280 | /* Replace array/object items with new ones. */ |
| 2281 | CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) |
| 2282 | { |
| 2283 | cJSON *after_inserted = NULL; |
| 2284 | |
| 2285 | if (which < 0 || newitem == NULL) |
| 2286 | { |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
| 2290 | after_inserted = get_array_item(array, (size_t)which); |
| 2291 | if (after_inserted == NULL) |
| 2292 | { |
| 2293 | return add_item_to_array(array, newitem); |
| 2294 | } |
| 2295 | |
| 2296 | if (after_inserted != array->child && after_inserted->prev == NULL) { |
| 2297 | /* return false if after_inserted is a corrupted array item */ |
| 2298 | return false; |
| 2299 | } |
| 2300 | |
| 2301 | newitem->next = after_inserted; |
| 2302 | newitem->prev = after_inserted->prev; |
| 2303 | after_inserted->prev = newitem; |
| 2304 | if (after_inserted == array->child) |
| 2305 | { |
| 2306 | array->child = newitem; |
| 2307 | } |
| 2308 | else |
| 2309 | { |
| 2310 | newitem->prev->next = newitem; |
| 2311 | } |
| 2312 | return true; |
| 2313 | } |
| 2314 | |
| 2315 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) |
| 2316 | { |
nothing calls this directly
no test coverage detected