MCPcopy Create free account
hub / github.com/Netis/cloud-probe / cJSON_InsertItemInArray

Function cJSON_InsertItemInArray

cpworker/src/cJSON/cJSON.c:2281–2313  ·  view source on GitHub ↗

Replace array/object items with new ones. */

Source from the content-addressed store, hash-verified

2279
2280/* Replace array/object items with new ones. */
2281CJSON_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
2315CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement)
2316{

Callers

nothing calls this directly

Calls 2

add_item_to_arrayFunction · 0.85
get_array_itemFunction · 0.70

Tested by

no test coverage detected