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