MCPcopy Create free account
hub / github.com/esnet/iperf / parse_object

Function parse_object

src/cjson.c:1612–1722  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

1610
1611/* Build an object from the text. */
1612static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer)
1613{
1614 cJSON *head = NULL; /* linked list head */
1615 cJSON *current_item = NULL;
1616
1617 if (input_buffer->depth >= CJSON_NESTING_LIMIT)
1618 {
1619 return false; /* to deeply nested */
1620 }
1621 input_buffer->depth++;
1622
1623 if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{'))
1624 {
1625 goto fail; /* not an object */
1626 }
1627
1628 input_buffer->offset++;
1629 buffer_skip_whitespace(input_buffer);
1630 if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}'))
1631 {
1632 goto success; /* empty object */
1633 }
1634
1635 /* check if we skipped to the end of the buffer */
1636 if (cannot_access_at_index(input_buffer, 0))
1637 {
1638 input_buffer->offset--;
1639 goto fail;
1640 }
1641
1642 /* step back to character in front of the first element */
1643 input_buffer->offset--;
1644 /* loop through the comma separated array elements */
1645 do
1646 {
1647 /* allocate next item */
1648 cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks));
1649 if (new_item == NULL)
1650 {
1651 goto fail; /* allocation failure */
1652 }
1653
1654 /* attach next item to list */
1655 if (head == NULL)
1656 {
1657 /* start the linked list */
1658 current_item = head = new_item;
1659 }
1660 else
1661 {
1662 /* add to the end and advance */
1663 current_item->next = new_item;
1664 new_item->prev = current_item;
1665 current_item = new_item;
1666 }
1667
1668 /* parse the name of the child */
1669 input_buffer->offset++;

Callers 1

parse_valueFunction · 0.85

Calls 5

buffer_skip_whitespaceFunction · 0.85
cJSON_New_ItemFunction · 0.85
parse_stringFunction · 0.85
parse_valueFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…