Commit a725fee3f670de5d91c44d54c0d1b4121ba28f13

Martin Mitas 2016-12-14T16:51:24

md_enter_child_containers: Fix crash (issue #10). Calling md_push_container_bytes() may result in ending a current block which may result in removing some contents from ctx->block_bytes when removing some lines with link reference definitions. This in effect means we have to end the block explicitly before storing the offset into the ctx->block_bytes.

diff --git a/md4c/md4c.c b/md4c/md4c.c
index 116a92f..fcb88a8 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -4678,7 +4678,9 @@ md_enter_child_containers(MD_CTX* ctx, int n_children)
             case _T('*'):
                 /* Remember offset in ctx->block_bytes so we can revisit the
                  * block if we detect it is a loose list. */
+                md_end_current_block(ctx);
                 c->block_byte_off = ctx->n_block_bytes;
+
                 MD_CHECK(md_push_container_bytes(ctx,
                                 (is_ordered_list ? MD_BLOCK_OL : MD_BLOCK_UL),
                                 c->start, MD_BLOCK_CONTAINER_OPENER));
diff --git a/test/coverage.txt b/test/coverage.txt
index e092048..8a05e51 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -63,3 +63,18 @@ att2=tok2> bar</p>
 bar</a></p>
 </blockquote>
 ````````````````````````````````
+
+### [Issue 10](https://github.com/mity/md4c/issues/10)
+```````````````````````````````` example
+[x]:
+x
+- <?
+
+  x
+.
+<ul>
+<li><?
+<p>x</p>
+</li>
+</ul>
+````````````````````````````````