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

Function insert_item_in_array

cpworker/src/cJSON/cJSON_Utils.c:703–738  ·  view source on GitHub ↗

non broken version of cJSON_InsertItemInArray */

Source from the content-addressed store, hash-verified

701
702/* non broken version of cJSON_InsertItemInArray */
703static cJSON_bool insert_item_in_array(cJSON *array, size_t which, cJSON *newitem)
704{
705 cJSON *child = array->child;
706 while (child && (which > 0))
707 {
708 child = child->next;
709 which--;
710 }
711 if (which > 0)
712 {
713 /* item is after the end of the array */
714 return 0;
715 }
716 if (child == NULL)
717 {
718 cJSON_AddItemToArray(array, newitem);
719 return 1;
720 }
721
722 /* insert into the linked list */
723 newitem->next = child;
724 newitem->prev = child->prev;
725 child->prev = newitem;
726
727 /* was it at the beginning */
728 if (child == array->child)
729 {
730 array->child = newitem;
731 }
732 else
733 {
734 newitem->prev->next = newitem;
735 }
736
737 return 1;
738}
739
740static cJSON *get_object_item(const cJSON *const object, const char *name, const cJSON_bool case_sensitive)
741{

Callers 1

apply_patchFunction · 0.85

Calls 1

cJSON_AddItemToArrayFunction · 0.85

Tested by

no test coverage detected