| 403 | */ |
| 404 | |
| 405 | static int |
| 406 | yaml_parser_load_mapping(yaml_parser_t *parser, yaml_event_t *first_event) |
| 407 | { |
| 408 | yaml_event_t event; |
| 409 | yaml_node_t node; |
| 410 | struct { |
| 411 | yaml_node_pair_t *start; |
| 412 | yaml_node_pair_t *end; |
| 413 | yaml_node_pair_t *top; |
| 414 | } pairs = { NULL, NULL, NULL }; |
| 415 | int index; |
| 416 | yaml_node_pair_t pair; |
| 417 | yaml_char_t *tag = first_event->data.mapping_start.tag; |
| 418 | |
| 419 | if (!STACK_LIMIT(parser, parser->document->nodes, INT_MAX-1)) goto error; |
| 420 | |
| 421 | if (!tag || strcmp((char *)tag, "!") == 0) { |
| 422 | yaml_free(tag); |
| 423 | tag = yaml_strdup((yaml_char_t *)YAML_DEFAULT_MAPPING_TAG); |
| 424 | if (!tag) goto error; |
| 425 | } |
| 426 | |
| 427 | if (!STACK_INIT(parser, pairs, INITIAL_STACK_SIZE)) goto error; |
| 428 | |
| 429 | MAPPING_NODE_INIT(node, tag, pairs.start, pairs.end, |
| 430 | first_event->data.mapping_start.style, |
| 431 | first_event->start_mark, first_event->end_mark); |
| 432 | |
| 433 | if (!PUSH(parser, parser->document->nodes, node)) goto error; |
| 434 | |
| 435 | index = (int)(parser->document->nodes.top - parser->document->nodes.start); |
| 436 | |
| 437 | if (!yaml_parser_register_anchor(parser, index, |
| 438 | first_event->data.mapping_start.anchor)) return 0; |
| 439 | |
| 440 | if (!yaml_parser_parse(parser, &event)) return 0; |
| 441 | |
| 442 | while (event.type != YAML_MAPPING_END_EVENT) { |
| 443 | if (!STACK_LIMIT(parser, |
| 444 | parser->document->nodes.start[index-1].data.mapping.pairs, |
| 445 | INT_MAX-1)) return 0; |
| 446 | pair.key = yaml_parser_load_node(parser, &event); |
| 447 | if (!pair.key) return 0; |
| 448 | if (!yaml_parser_parse(parser, &event)) return 0; |
| 449 | pair.value = yaml_parser_load_node(parser, &event); |
| 450 | if (!pair.value) return 0; |
| 451 | if (!PUSH(parser, |
| 452 | parser->document->nodes.start[index-1].data.mapping.pairs, |
| 453 | pair)) return 0; |
| 454 | if (!yaml_parser_parse(parser, &event)) return 0; |
| 455 | } |
| 456 | |
| 457 | parser->document->nodes.start[index-1].end_mark = event.end_mark; |
| 458 | |
| 459 | return index; |
| 460 | |
| 461 | error: |
| 462 | yaml_free(tag); |
no test coverage detected