Build an array from input text. */
| 1341 | |
| 1342 | /* Build an array from input text. */ |
| 1343 | static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) |
| 1344 | { |
| 1345 | cJSON *head = NULL; /* head of the linked list */ |
| 1346 | cJSON *current_item = NULL; |
| 1347 | |
| 1348 | if (input_buffer->depth >= CJSON_NESTING_LIMIT) |
| 1349 | { |
| 1350 | return false; /* to deeply nested */ |
| 1351 | } |
| 1352 | input_buffer->depth++; |
| 1353 | |
| 1354 | if (buffer_at_offset(input_buffer)[0] != '[') |
| 1355 | { |
| 1356 | /* not an array */ |
| 1357 | goto fail; |
| 1358 | } |
| 1359 | |
| 1360 | input_buffer->offset++; |
| 1361 | buffer_skip_whitespace(input_buffer); |
| 1362 | if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) |
| 1363 | { |
| 1364 | /* empty array */ |
| 1365 | goto success; |
| 1366 | } |
| 1367 | |
| 1368 | /* check if we skipped to the end of the buffer */ |
| 1369 | if (cannot_access_at_index(input_buffer, 0)) |
| 1370 | { |
| 1371 | input_buffer->offset--; |
| 1372 | goto fail; |
| 1373 | } |
| 1374 | |
| 1375 | /* step back to character in front of the first element */ |
| 1376 | input_buffer->offset--; |
| 1377 | /* loop through the comma separated array elements */ |
| 1378 | do |
| 1379 | { |
| 1380 | /* allocate next item */ |
| 1381 | cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); |
| 1382 | if (new_item == NULL) |
| 1383 | { |
| 1384 | goto fail; /* allocation failure */ |
| 1385 | } |
| 1386 | |
| 1387 | /* attach next item to list */ |
| 1388 | if (head == NULL) |
| 1389 | { |
| 1390 | /* start the linked list */ |
| 1391 | current_item = head = new_item; |
| 1392 | } |
| 1393 | else |
| 1394 | { |
| 1395 | /* add to the end and advance */ |
| 1396 | current_item->next = new_item; |
| 1397 | new_item->prev = current_item; |
| 1398 | current_item = new_item; |
| 1399 | } |
| 1400 |
no test coverage detected