From 31509b0d5654baf2e2c3438cae90c30e3dd00c17 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 9 Nov 2013 14:12:22 +0100 Subject: fix slurp(), it needs to read size-1 for the trailing NUL --- src/general.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/general.c b/src/general.c index bf7afd1..7ec80a8 100644 --- a/src/general.c +++ b/src/general.c @@ -19,7 +19,8 @@ bool slurp(const char *filename, char *destination, int size) { if ((fd = open(filename, O_RDONLY)) == -1) return false; - int n = read(fd, destination, size); + /* We need one byte for the trailing 0 byte */ + int n = read(fd, destination, size-1); if (n != -1) destination[n] = '\0'; (void)close(fd); -- cgit v1.2.3