Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cell_index is not initialized when a table cell is created using cmark_node_new_with_ext() #360

@steffen-kiess

Description

@steffen-kiess

Starting with commit 5e8ad61 a table cell keeps track of its index. When creating a table cell with cmark_node_new_with_ext(), the cell_index value is not initialized anywhere. This will cause functions like cmark_render_html() and cmark_render_xml() to crash.

Example code:

#include <string.h>

#include <cmark-gfm.h>
#include <cmark-gfm-core-extensions.h>

const char* doc_str = "\n"
"| foo | bar |\n"
"| --- | --- |\n"
"| baz | bim |\n"
"";

int main() {
  cmark_gfm_core_extensions_ensure_registered();
  cmark_parser* parser = cmark_parser_new(0);
  cmark_parser_attach_syntax_extension(parser, cmark_find_syntax_extension("table"));
  cmark_parser_feed(parser, doc_str, strlen(doc_str));
  cmark_node* doc = cmark_parser_finish(parser);

  const char* html = cmark_render_html(doc, 0, 0);
  printf("%s\n", html);

  const char* xml = cmark_render_xml(doc, 0);
  printf("%s\n", xml);

  cmark_node* table = cmark_node_first_child(doc);
  cmark_node* header = cmark_node_first_child(table);
  cmark_node* cell = cmark_node_first_child(header);
  printf("cell is a '%s'\n", cmark_node_get_type_string(cell));

  cmark_node* new_cell = cmark_node_new_with_ext(cmark_node_get_type(cell), cmark_node_get_syntax_extension(cell));
  printf("new_cell is a '%s'\n", cmark_node_get_type_string(new_cell));

  cmark_node_prepend_child(header, new_cell);
  cmark_node_unlink(cell);

  const char* html2 = cmark_render_html(doc, 0, 0);
  printf("%s\n", html2);

  const char* xml2 = cmark_render_xml(doc, 0);
  printf("%s\n", xml2);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions