From 67f760a78f7a875216d9b64aaf3524cc4f9a0f48 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 3 Jul 2016 12:18:43 +0200 Subject: Fix chunk_set_cstr with suffix of current string It's possible that cmark_chunk_set_cstr is called with a substring (suffix) of the current string. Delay freeing of the chunk content to handle this case correctly. Fixes issue #139. --- api_test/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'api_test/main.c') diff --git a/api_test/main.c b/api_test/main.c index 8da9ba9..94051e9 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -171,7 +171,13 @@ static void accessors(test_batch_runner *runner) { OK(runner, cmark_node_set_url(link, "URL"), "set_url"); OK(runner, cmark_node_set_title(link, "TITLE"), "set_title"); - OK(runner, cmark_node_set_literal(string, "LINK"), "set_literal string"); + OK(runner, cmark_node_set_literal(string, "prefix-LINK"), + "set_literal string"); + + // Set literal to suffix of itself (issue #139). + const char *literal = cmark_node_get_literal(string); + OK(runner, cmark_node_set_literal(string, literal + sizeof("prefix")), + "set_literal suffix"); char *rendered_html = cmark_render_html(doc, CMARK_OPT_DEFAULT); static const char expected_html[] = -- cgit v1.2.3