From 26b683ca743755d1959269cdc15dbd38c4a89aa0 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 15 Jul 2021 21:19:34 -0700 Subject: Bugfix for NULL bytes in text --- files.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'files.c') diff --git a/files.c b/files.c index 9eeec3d..d010cc0 100644 --- a/files.c +++ b/files.c @@ -38,8 +38,14 @@ static void populate_lines(file_t *f, size_t len) if (n >= linecap) f->lines = xrealloc(f->lines, sizeof(const char*)*(linecap *= 2)); f->lines[n] = p; - p = strchr(p, '\n'); - if (p) ++p; + do { + char *nl = strchr(p, '\n'); + if (nl) { + p = nl+1; + break; + } else if (p < &f->memory[len]) + p += strlen(p)+1; + } while (p < &f->memory[len]); } } -- cgit v1.2.3