diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-09-25 01:32:31 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-09-25 01:32:31 -0700 |
| commit | 17c90ebe52f7236da137454dbc9581c9e7d65b4c (patch) | |
| tree | 1f2378da20c38849f41d5c983e87a4b3f5994561 | |
| parent | 8ca1efeff936ba98d03de53001c761da214af9b4 (diff) | |
Bugfix for empty files and cleanup since memchr is doing good work
| -rw-r--r-- | files.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -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; } } |
