md_mark_chain_append: Set next of the tail mark to -1. Fixes #104.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
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>
+````````````````````````````````