From: Michael Stapelberg Date: Sat, 9 Nov 2013 13:12:22 +0000 (+0100) Subject: fix slurp(), it needs to read size-1 for the trailing NUL X-Git-Tag: 2.8~8 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=31509b0d5654baf2e2c3438cae90c30e3dd00c17;p=i3%2Fi3status fix slurp(), it needs to read size-1 for the trailing NUL --- 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);