Skip to content

Commit de6feae

Browse files
committed
Added check for underflows when duping footnote ref literal.
1 parent 586a22d commit de6feae

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/inlines.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,13 @@ static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) {
11681168
//
11691169
// this copies the footnote reference string, even if between the
11701170
// `opener` and the subject's current position there are other nodes
1171-
fnref->as.literal = cmark_chunk_dup(literal, 1, (fnref_end_column - fnref_start_column) - 2);
1171+
//
1172+
// (first, check for underflows)
1173+
if ((fnref_start_column + 2) <= fnref_end_column) {
1174+
fnref->as.literal = cmark_chunk_dup(literal, 1, (fnref_end_column - fnref_start_column) - 2);
1175+
} else {
1176+
fnref->as.literal = cmark_chunk_dup(literal, 1, 0);
1177+
}
11721178

11731179
fnref->start_line = fnref->end_line = subj->line;
11741180
fnref->start_column = fnref_start_column;

0 commit comments

Comments
 (0)