aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-09-25 01:32:31 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-09-25 01:32:31 -0700
commit17c90ebe52f7236da137454dbc9581c9e7d65b4c (patch)
tree1f2378da20c38849f41d5c983e87a4b3f5994561
parent8ca1efeff936ba98d03de53001c761da214af9b4 (diff)
Bugfix for empty files and cleanup since memchr is doing good work
-rw-r--r--files.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/files.c b/files.c
index 26c6535..22eaed1 100644
--- a/files.c
+++ b/files.c
@@ -27,19 +27,14 @@ static void populate_lines(file_t *f)
f->lines = new(const char*[linecap]);
f->nlines = 0;
char *p = f->start;
- for (size_t n = 0; p && p < f->end; ++n) {
+ for (size_t n = 0; p && p <= f->end; ++n) {
++f->nlines;
if (n >= linecap)
f->lines = grow(f->lines, linecap *= 2);
f->lines[n] = p;
- do {
- char *nl = memchr(p, '\n', (size_t)(f->end - p));
- if (nl) {
- p = nl+1;
- break;
- } else if (p < f->end)
- p += strlen(p)+1;
- } while (p < f->end);
+ char *nl = memchr(p, '\n', (size_t)(f->end - p));
+ if (nl && nl < f->end) p = nl+1;
+ else break;
}
}