Commit f0175cfcb7a6ae10eeb48ace283808235fc6206d

Martin Mitas 2016-12-07T15:08:41

md_do_normalize_string: Fix checking whether we are done.

diff --git a/md4c/md4c.c b/md4c/md4c.c
index 520b0ef..e567605 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -859,13 +859,10 @@ md_do_normalize_string(MD_CTX* ctx, OFF beg, OFF end, const MD_LINE* lines, int 
     while(1) {
         const MD_LINE* line = &lines[line_index];
         OFF line_end = line->end;
+        if(end < line_end)
+            line_end = end;
 
         while(off < line_end) {
-            if(off >= end) {
-                *p_size = ptr - buffer;
-                return;
-            }
-
             if(resolve_escapes  &&  CH(off) == _T('\\')  &&
                off+1 < end  &&  (ISPUNCT(off+1) || ISNEWLINE(off+1))) {
                 if(ISNEWLINE(off+1))
@@ -878,6 +875,11 @@ md_do_normalize_string(MD_CTX* ctx, OFF beg, OFF end, const MD_LINE* lines, int 
             off++;
         }
 
+        if(off >= end) {
+            *p_size = ptr - buffer;
+            return;
+        }
+
         *ptr = line_break_replacement_char;
         ptr++;