MCPcopy Index your code
hub / github.com/DaveGamble/cJSON / cJSON_InsertItemInArray

Function cJSON_InsertItemInArray

cJSON.c:2319–2351  ·  view source on GitHub ↗

Replace array/object items with new ones. */

Source from the content-addressed store, hash-verified

2317
2318/* Replace array/object items with new ones. */
2319CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem)
2320{
2321 cJSON *after_inserted = NULL;
2322
2323 if (which < 0 || newitem == NULL)
2324 {
2325 return false;
2326 }
2327
2328 after_inserted = get_array_item(array, (size_t)which);
2329 if (after_inserted == NULL)
2330 {
2331 return add_item_to_array(array, newitem);
2332 }
2333
2334 if (after_inserted != array->child && after_inserted->prev == NULL) {
2335 /* return false if after_inserted is a corrupted array item */
2336 return false;
2337 }
2338
2339 newitem->next = after_inserted;
2340 newitem->prev = after_inserted->prev;
2341 after_inserted->prev = newitem;
2342 if (after_inserted == array->child)
2343 {
2344 array->child = newitem;
2345 }
2346 else
2347 {
2348 newitem->prev->next = newitem;
2349 }
2350 return true;
2351}
2352
2353CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2354{

Calls 2

add_item_to_arrayFunction · 0.85
get_array_itemFunction · 0.70

Used in the wild real call sites across dependent graphs

searching dependent graphs…