Replace array/object items with new ones. */
| 2332 | |
| 2333 | /* Replace array/object items with new ones. */ |
| 2334 | CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) |
| 2335 | { |
| 2336 | cJSON *after_inserted = NULL; |
| 2337 | |
| 2338 | if (which < 0 || newitem == NULL) |
| 2339 | { |
| 2340 | return false; |
| 2341 | } |
| 2342 | |
| 2343 | after_inserted = get_array_item(array, (size_t)which); |
| 2344 | if (after_inserted == NULL) |
| 2345 | { |
| 2346 | return add_item_to_array(array, newitem); |
| 2347 | } |
| 2348 | |
| 2349 | if (after_inserted != array->child && after_inserted->prev == NULL) { |
| 2350 | /* return false if after_inserted is a corrupted array item */ |
| 2351 | return false; |
| 2352 | } |
| 2353 | |
| 2354 | newitem->next = after_inserted; |
| 2355 | newitem->prev = after_inserted->prev; |
| 2356 | after_inserted->prev = newitem; |
| 2357 | if (after_inserted == array->child) |
| 2358 | { |
| 2359 | array->child = newitem; |
| 2360 | } |
| 2361 | else |
| 2362 | { |
| 2363 | newitem->prev->next = newitem; |
| 2364 | } |
| 2365 | return true; |
| 2366 | } |
| 2367 | |
| 2368 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) |
| 2369 | { |
nothing calls this directly
no test coverage detected