Skip to content

Commit

Permalink
Expose CMARK_NODE_FOOTNOTE_DEFINION literal value.
Browse files Browse the repository at this point in the history
In addition, fix a bug where the length of the literal value was
calculated AFTER the actual literal string (null terminated) was
allocated.
  • Loading branch information
ioquatix committed Jun 19, 2023
1 parent 2d65cd3 commit ab19806
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,13 @@ static void open_new_blocks(cmark_parser *parser, cmark_node **container,
parser->options & CMARK_OPT_FOOTNOTES &&
(matched = scan_footnote_definition(input, parser->first_nonspace))) {
cmark_chunk c = cmark_chunk_dup(input, parser->first_nonspace + 2, matched - 2);
cmark_chunk_to_cstr(parser->mem, &c);

while (c.data[c.len - 1] != ']')
--c.len;
--c.len;

cmark_chunk_to_cstr(parser->mem, &c);

S_advance_offset(parser, input, parser->first_nonspace + matched - parser->offset, false);
*container = add_child(parser, *container, CMARK_NODE_FOOTNOTE_DEFINITION, parser->first_nonspace + matched + 1);
(*container)->as.literal = c;
Expand Down
2 changes: 2 additions & 0 deletions src/node.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>

#include "cmark-gfm.h"
#include "config.h"
#include "node.h"
#include "syntax_extension.h"
Expand Down Expand Up @@ -377,6 +378,7 @@ const char *cmark_node_get_literal(cmark_node *node) {
case CMARK_NODE_HTML_INLINE:
case CMARK_NODE_CODE:
case CMARK_NODE_FOOTNOTE_REFERENCE:
case CMARK_NODE_FOOTNOTE_DEFINITION:
return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.literal);

case CMARK_NODE_CODE_BLOCK:
Expand Down

0 comments on commit ab19806

Please sign in to comment.