From 3739c54c9a3ce1f79452548a49f82878868fa6d0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 11 Nov 2014 12:51:54 -0800 Subject: Improved cmark_markdown_to_html. Added length parameter so we can avoid strlen. Properly free buffer. --- src/cmark.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/cmark.c') diff --git a/src/cmark.c b/src/cmark.c index 064c080..ef98d79 100644 --- a/src/cmark.c +++ b/src/cmark.c @@ -5,15 +5,19 @@ #include "cmark.h" #include "buffer.h" -extern unsigned char *cmark_markdown_to_html(unsigned char *text) +extern unsigned char *cmark_markdown_to_html(unsigned char *text, int len) { node_block *blocks; strbuf htmlbuf = GH_BUF_INIT; + unsigned char *result; - blocks = cmark_parse_document(text, sizeof(text)); + blocks = cmark_parse_document(text, len); cmark_render_html(&htmlbuf, blocks); cmark_free_nodes(blocks); - return strbuf_detach(&htmlbuf); + result = strbuf_detach(&htmlbuf); + strbuf_free(&htmlbuf); + + return result; } -- cgit v1.2.3