- Commit
- d929a2983db96be22277c2052ea61cd8ec7ac6f1
- Parent
- 4570eb2bff2e1b71fa5b6408abbc69c98ff5ff24
- Author
- John MacFarlane <jgm@berkeley.edu>
- Date
Merge pull request #215 from nwellnhof/no_trailing_newline
Fix segfault on docs without trailing newline
My personal build of CMark ✏️
Merge pull request #215 from nwellnhof/no_trailing_newline
Fix segfault on docs without trailing newline
2 files changed, 14 insertions, 1 deletion
Status | File Name | N° Changes | Insertions | Deletions |
Modified | api_test/main.c | 13 | 13 | 0 |
Modified | src/blocks.c | 2 | 1 | 1 |
diff --git a/api_test/main.c b/api_test/main.c @@ -441,6 +441,18 @@ test_content(test_batch_runner *runner, cmark_node_type type, } static void +parser(test_batch_runner *runner) +{ + static const char markdown[] = "No newline"; + cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1); + char *html = cmark_render_html(doc); + STR_EQ(runner, html, "<p>No newline</p>\n", + "document without trailing newline"); + free(html); + cmark_node_destroy(doc); +} + +static void render_html(test_batch_runner *runner) { char *html; @@ -479,6 +491,7 @@ int main() { node_check(runner); create_tree(runner); hierarchy(runner); + parser(runner); render_html(runner); test_print_summary(runner);
diff --git a/src/blocks.c b/src/blocks.c @@ -441,7 +441,7 @@ extern cmark_node *cmark_parse_document(const char *buffer, size_t len) while (buffer < end) { const char *eol = memchr(buffer, '\n', end - buffer); - offset = eol ? (eol - buffer) + 1 : eol - buffer; + offset = eol ? (eol - buffer) + 1 : end - buffer; cmark_process_line(parser, buffer, offset); buffer += offset; linenum++;