Replace array/object items with new ones. */
| 2266 | |
| 2267 | /* Replace array/object items with new ones. */ |
| 2268 | CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) |
| 2269 | { |
| 2270 | cJSON *after_inserted = NULL; |
| 2271 | |
| 2272 | if (which < 0 || newitem == NULL) |
| 2273 | { |
| 2274 | return false; |
| 2275 | } |
| 2276 | |
| 2277 | after_inserted = get_array_item(array, (size_t)which); |
| 2278 | if (after_inserted == NULL) |
| 2279 | { |
| 2280 | return add_item_to_array(array, newitem); |
| 2281 | } |
| 2282 | |
| 2283 | if (after_inserted != array->child && after_inserted->prev == NULL) { |
| 2284 | /* return false if after_inserted is a corrupted array item */ |
| 2285 | return false; |
| 2286 | } |
| 2287 | |
| 2288 | newitem->next = after_inserted; |
| 2289 | newitem->prev = after_inserted->prev; |
| 2290 | after_inserted->prev = newitem; |
| 2291 | if (after_inserted == array->child) |
| 2292 | { |
| 2293 | array->child = newitem; |
| 2294 | } |
| 2295 | else |
| 2296 | { |
| 2297 | newitem->prev->next = newitem; |
| 2298 | } |
| 2299 | return true; |
| 2300 | } |
| 2301 | |
| 2302 | CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) |
| 2303 | { |
nothing calls this directly
no test coverage detected