Skip to content

Commit 3658f34

Browse files
committed
Move nesting limit to scanner only
The scanner now checks combined block+flow nesting depth, making the parser-level checks redundant. Remove them and unify the flow-level check to use STACK_LIMIT for consistency with roll_indent.
1 parent b9106ba commit 3658f34

2 files changed

Lines changed: 1 addition & 30 deletions

File tree

src/parser.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ yaml_parser_set_parser_error_context(yaml_parser_t *parser,
8282
const char *context, yaml_mark_t context_mark,
8383
const char *problem, yaml_mark_t problem_mark);
8484

85-
static int
86-
yaml_maximum_level_reached(yaml_parser_t *parser,
87-
yaml_mark_t context_mark, yaml_mark_t problem_mark);
88-
8985
/*
9086
* State functions.
9187
*/
@@ -229,15 +225,6 @@ yaml_parser_set_parser_error_context(yaml_parser_t *parser,
229225
return 0;
230226
}
231227

232-
static int
233-
yaml_maximum_level_reached(yaml_parser_t *parser,
234-
yaml_mark_t context_mark, yaml_mark_t problem_mark)
235-
{
236-
yaml_parser_set_parser_error_context(parser,
237-
"while parsing", context_mark, "Maximum nesting level reached, set with yaml_set_max_nest_level())", problem_mark);
238-
return 0;
239-
}
240-
241228
/*
242229
* State dispatcher.
243230
*/
@@ -677,43 +664,27 @@ yaml_parser_parse_node(yaml_parser_t *parser, yaml_event_t *event,
677664
return 1;
678665
}
679666
else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) {
680-
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
681-
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
682-
goto error;
683-
}
684667
end_mark = token->end_mark;
685668
parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
686669
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
687670
YAML_FLOW_SEQUENCE_STYLE, start_mark, end_mark);
688671
return 1;
689672
}
690673
else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) {
691-
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
692-
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
693-
goto error;
694-
}
695674
end_mark = token->end_mark;
696675
parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
697676
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
698677
YAML_FLOW_MAPPING_STYLE, start_mark, end_mark);
699678
return 1;
700679
}
701680
else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) {
702-
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
703-
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
704-
goto error;
705-
}
706681
end_mark = token->end_mark;
707682
parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
708683
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
709684
YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark);
710685
return 1;
711686
}
712687
else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) {
713-
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
714-
yaml_maximum_level_reached(parser, start_mark, token->start_mark);
715-
goto error;
716-
}
717688
end_mark = token->end_mark;
718689
parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
719690
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,

src/scanner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser)
11811181
return 0;
11821182
}
11831183

1184-
if (parser->flow_level + (int)(parser->indents.top - parser->indents.start) >= MAX_NESTING_LEVEL) {
1184+
if (!STACK_LIMIT(parser, parser->indents, MAX_NESTING_LEVEL - parser->flow_level)) {
11851185
return yaml_parser_set_scanner_error(parser,
11861186
"while increasing flow level", parser->mark,
11871187
"exceeded maximum nesting depth");

0 commit comments

Comments
 (0)