From 300b31b2dfb3ee7a84c78bd2802cb5649d0dc1ba Mon Sep 17 00:00:00 2001 From: Sam Newbold Date: Mon, 10 Jun 2019 16:29:37 +0200 Subject: print_file_contents: allocate enough to include \0 related to #331 Previously, if max_chars was read, the null byte would be written past the end of buf. --- src/print_file_contents.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/print_file_contents.c') diff --git a/src/print_file_contents.c b/src/print_file_contents.c index afbe3e3..91ad80e 100644 --- a/src/print_file_contents.c +++ b/src/print_file_contents.c @@ -23,7 +23,7 @@ static void *scalloc(size_t size) { void print_file_contents(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_bad, const int max_chars) { const char *walk = format; char *outwalk = buffer; - char *buf = scalloc(max_chars * sizeof(char)); + char *buf = scalloc(max_chars * sizeof(char) + 1); int n = -1; int fd = open(path, O_RDONLY); -- cgit v1.2.3