Build an array from input text. */
| 1490 | |
| 1491 | /* Build an array from input text. */ |
| 1492 | static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) |
| 1493 | { |
| 1494 | cJSON *head = NULL; /* head of the linked list */ |
| 1495 | cJSON *current_item = NULL; |
| 1496 | |
| 1497 | if (input_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1498 | { |
| 1499 | return false; /* to deeply nested */ |
| 1500 | } |
| 1501 | input_buffer->depth++; |
| 1502 | |
| 1503 | if (buffer_at_offset(input_buffer)[0] != '[') |
| 1504 | { |
| 1505 | /* not an array */ |
| 1506 | goto fail; |
| 1507 | } |
| 1508 | |
| 1509 | input_buffer->offset++; |
| 1510 | buffer_skip_whitespace(input_buffer); |
| 1511 | if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) |
| 1512 | { |
| 1513 | /* empty array */ |
| 1514 | goto success; |
| 1515 | } |
| 1516 | |
| 1517 | /* check if we skipped to the end of the buffer */ |
| 1518 | if (cannot_access_at_index(input_buffer, 0)) |
| 1519 | { |
| 1520 | input_buffer->offset--; |
| 1521 | goto fail; |
| 1522 | } |
| 1523 | |
| 1524 | /* step back to character in front of the first element */ |
| 1525 | input_buffer->offset--; |
| 1526 | /* loop through the comma separated array elements */ |
| 1527 | do |
| 1528 | { |
| 1529 | /* allocate next item */ |
| 1530 | cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); |
| 1531 | if (new_item == NULL) |
| 1532 | { |
| 1533 | goto fail; /* allocation failure */ |
| 1534 | } |
| 1535 | |
| 1536 | /* attach next item to list */ |
| 1537 | if (head == NULL) |
| 1538 | { |
| 1539 | /* start the linked list */ |
| 1540 | current_item = head = new_item; |
| 1541 | } |
| 1542 | else |
| 1543 | { |
| 1544 | /* add to the end and advance */ |
| 1545 | current_item->next = new_item; |
| 1546 | new_item->prev = current_item; |
| 1547 | current_item = new_item; |
| 1548 | } |
| 1549 |
no test coverage detected
searching dependent graphs…