cmark

My personal build of CMark ✏️

Commit
6db3cb40add3800246bee8cd051baf4243e8ae44
Parent
039913a8fe92b0f07b4bee418bc4df0ed85c7811
Author
John MacFarlane <jgm@berkeley.edu>
Date

Another small optimization in _scan_at.

Check for offset greater than string length.

Diffstat

2 files changed, 3 insertions, 4 deletions

Status File Name N° Changes Insertions Deletions
Modified src/scanners.c 5 2 3
Modified src/scanners.re 2 1 1
diff --git a/src/scanners.c b/src/scanners.c
@@ -7,10 +7,9 @@ bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c,
                    bufsize_t offset) {
   bufsize_t res;
   unsigned char *ptr = (unsigned char *)c->data;
-  unsigned char zero = '\0';
 
-  if (ptr == NULL) {
-    res = scanner(&zero);
+  if (ptr == NULL || offset > c->len) {
+    return 0;
   } else {
     unsigned char lim = ptr[c->len];
 
diff --git a/src/scanners.re b/src/scanners.re
@@ -7,7 +7,7 @@ bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c, 
 	bufsize_t res;
 	unsigned char *ptr = (unsigned char *)c->data;
 
-        if (ptr == NULL) {
+        if (ptr == NULL || offset > c->len) {
           return 0;
         } else {
 	  unsigned char lim = ptr[c->len];