Skip to content

Commit

Permalink
Add a flag to avoid quadratic loop in try_opening_table_header
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse committed Oct 9, 2022
1 parent 9d57d8a commit 9f02cba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions extensions/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
const char *parent_string;
uint16_t i;

if (parent_container->flags & CMARK_NODE__TABLE_VISITED) {
return parent_container;
}

if (!scan_table_start(input, len, cmark_parser_get_first_nonspace(parser))) {
return parent_container;
}
Expand Down Expand Up @@ -267,6 +271,7 @@ static cmark_node *try_opening_table_header(cmark_syntax_extension *self,
free_table_row(parser->mem, marker_row);
free_table_row(parser->mem, header_row);
cmark_arena_pop();
parent_container->flags |= CMARK_NODE__TABLE_VISITED;
return parent_container;
}

Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum cmark_node__internal_flags {
CMARK_NODE__OPEN = (1 << 0),
CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
CMARK_NODE__TABLE_VISITED = (1 << 3),
};

struct cmark_node {
Expand Down

0 comments on commit 9f02cba

Please sign in to comment.