Build an array from input text. */
| 1450 | |
| 1451 | /* Build an array from input text. */ |
| 1452 | static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) |
| 1453 | { |
| 1454 | cJSON *head = NULL; /* head of the linked list */ |
| 1455 | cJSON *current_item = NULL; |
| 1456 | |
| 1457 | if (input_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1458 | { |
| 1459 | return false; /* to deeply nested */ |
| 1460 | } |
| 1461 | input_buffer->depth++; |
| 1462 | |
| 1463 | if (buffer_at_offset(input_buffer)[0] != '[') |
| 1464 | { |
| 1465 | /* not an array */ |
| 1466 | goto fail; |
| 1467 | } |
| 1468 | |
| 1469 | input_buffer->offset++; |
| 1470 | buffer_skip_whitespace(input_buffer); |
| 1471 | if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) |
| 1472 | { |
| 1473 | /* empty array */ |
| 1474 | goto success; |
| 1475 | } |
| 1476 | |
| 1477 | /* check if we skipped to the end of the buffer */ |
| 1478 | if (cannot_access_at_index(input_buffer, 0)) |
| 1479 | { |
| 1480 | input_buffer->offset--; |
| 1481 | goto fail; |
| 1482 | } |
| 1483 | |
| 1484 | /* step back to character in front of the first element */ |
| 1485 | input_buffer->offset--; |
| 1486 | /* loop through the comma separated array elements */ |
| 1487 | do |
| 1488 | { |
| 1489 | /* allocate next item */ |
| 1490 | cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); |
| 1491 | if (new_item == NULL) |
| 1492 | { |
| 1493 | goto fail; /* allocation failure */ |
| 1494 | } |
| 1495 | |
| 1496 | /* attach next item to list */ |
| 1497 | if (head == NULL) |
| 1498 | { |
| 1499 | /* start the linked list */ |
| 1500 | current_item = head = new_item; |
| 1501 | } |
| 1502 | else |
| 1503 | { |
| 1504 | /* add to the end and advance */ |
| 1505 | current_item->next = new_item; |
| 1506 | new_item->prev = current_item; |
| 1507 | current_item = new_item; |
| 1508 | } |
| 1509 |
no test coverage detected
searching dependent graphs…