From: Michael Stapelberg Date: Wed, 13 Jul 2011 17:17:24 +0000 (+0200) Subject: slurp(): null-terminate buffer (Thanks mist) X-Git-Tag: 2.3~7 X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3status;a=commitdiff_plain;h=2e621680c4efc394df2c66535ded6bd6b5a060b8 slurp(): null-terminate buffer (Thanks mist) --- diff --git a/src/general.c b/src/general.c index 2ae90f1..bf7afd1 100644 --- a/src/general.c +++ b/src/general.c @@ -19,7 +19,9 @@ bool slurp(const char *filename, char *destination, int size) { if ((fd = open(filename, O_RDONLY)) == -1) return false; - (void)read(fd, destination, size); + int n = read(fd, destination, size); + if (n != -1) + destination[n] = '\0'; (void)close(fd); return true;