cmark

My personal build of CMark ✏️

Commit
89c8d703d258cef7cbe566eab537fb8f30aad7ed
Parent
1f51da22e4d56ae0f0bc3ae75817e99a91038226
Author
John MacFarlane <jgm@berkeley.edu>
Date

Changed logic for null/eol checks.

- only check once for "not at end of line" - check for null before we check for newline characters (the previous patch would fail for NULL + CR)

See #160.

Diffstat

1 file changed, 14 insertions, 9 deletions

Status File Name N° Changes Insertions Deletions
Modified src/blocks.c 23 14 9
diff --git a/src/blocks.c b/src/blocks.c
@@ -569,16 +569,21 @@ static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer,
     }
 
     buffer += chunk_len;
-    // skip over line ending characters:
-    if (buffer < end && *buffer == '\r') {
-      buffer++;
-      if (buffer == end)
-        parser->last_buffer_ended_with_cr = true;
+    if (buffer < end) {
+      if (*buffer == '\0') {
+	// skip over NULL
+	buffer++;
+      } else {
+        // skip over line ending characters
+        if (*buffer == '\r') {
+          buffer++;
+          if (buffer == end)
+            parser->last_buffer_ended_with_cr = true;
+	}
+        if (*buffer == '\n')
+          buffer++;
+      }
     }
-    if (buffer < end && *buffer == '\0')
-      buffer++;
-    else if (buffer < end && *buffer == '\n')
-      buffer++;
   }
 }