Commit 403043bba3f3865d45ac7c537797ff69fd90ae46

Martin Mitas 2020-01-16T16:15:08

md_mark_chain_append: Set next of the tail mark to -1. Fixes #104.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8aec50a..cbc00ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,9 @@ Fixes:
    Fixed an off-by-one error in the maximal length limit of some segments
    of e-mail addresses used in autolinks.
 
+ * [#104](https://github.com/mity/md4c/issues/104):
+   Fix an infinite loop when tables (`MD_FLAG_TABLES`) and links are combined.
+
 
 ## Version 0.4.2
 
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 1520545..c951d85 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -2531,6 +2531,7 @@ md_mark_chain_append(MD_CTX* ctx, MD_MARKCHAIN* chain, int mark_index)
         chain->head = mark_index;
 
     ctx->marks[mark_index].prev = chain->tail;
+    ctx->marks[mark_index].next = -1;
     chain->tail = mark_index;
 }
 
@@ -3577,7 +3578,7 @@ md_resolve_links(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
 
             MD_ASSERT(ctx->marks[opener_index+2].ch == 'D');
             md_mark_store_ptr(ctx, opener_index+2, attr.title);
-            if(!IS_INPUT_STR(attr.title))
+            if(attr.title != NULL  &&  !IS_INPUT_STR(attr.title))
                 md_mark_chain_append(ctx, &PTR_CHAIN, opener_index+2);
             ctx->marks[opener_index+2].prev = attr.title_size;
 
diff --git a/test/tables.txt b/test/tables.txt
index de61f7d..80147ab 100644
--- a/test/tables.txt
+++ b/test/tables.txt
@@ -337,3 +337,27 @@ But the last line is not part of it due its indentation.)
 </tbody>
 </table>
 ````````````````````````````````
+
+
+### [Issue 104](https://github.com/mity/md4c/issues/104)
+
+```````````````````````````````` example
+A | B
+--- | ---
+[x](url)
+.
+<table>
+<thead>
+<tr>
+<th>A</th>
+<th>B</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td><a href="url">x</a></td>
+<td></td>
+</tr>
+</tbody>
+</table>
+````````````````````````````````