diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-12-28 10:50:20 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-12-28 10:50:20 -0800 |
commit | 6db3cb40add3800246bee8cd051baf4243e8ae44 (patch) | |
tree | 52716cb7140b01d2e941272c34f447ad21869558 /src | |
parent | 039913a8fe92b0f07b4bee418bc4df0ed85c7811 (diff) |
Another small optimization in _scan_at.
Check for offset greater than string length.
Diffstat (limited to 'src')
-rw-r--r-- | src/scanners.c | 5 | ||||
-rw-r--r-- | src/scanners.re | 2 |
2 files changed, 3 insertions, 4 deletions
diff --git a/src/scanners.c b/src/scanners.c index c0df18b..ae4125f 100644 --- 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 index befe7d0..8176590 100644 --- 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]; |