aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-07-15 21:19:34 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-07-15 21:19:34 -0700
commit26b683ca743755d1959269cdc15dbd38c4a89aa0 (patch)
tree6b0fd681c67182deeba4b0d71ac7b0055128cdc5
parent7cd6117138ec08ca1af0ddf36185204bb719dd31 (diff)
Bugfix for NULL bytes in text
-rw-r--r--files.c10
-rw-r--r--print.c3
2 files changed, 10 insertions, 3 deletions
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]);
}
}
diff --git a/print.c b/print.c
index 40b6058..8638876 100644
--- a/print.c
+++ b/print.c
@@ -216,7 +216,8 @@ static void print_between(FILE *out, printer_t *pr, const char *start, const cha
fprintf(out, "%s", color);
current_color = color;
}
- fprintf(out, "%.*s", (int)(eol - start), start);
+ for (const char *c = start; c < eol; c++)
+ fputc(*c, out);
if (eol[-1] == '\n')
pr->needs_line_number = 1;
start = eol;