]> git.sur5r.net Git - i3/i3status/commitdiff
fix slurp(), it needs to read size-1 for the trailing NUL
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 9 Nov 2013 13:12:22 +0000 (14:12 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 9 Nov 2013 13:37:04 +0000 (14:37 +0100)
src/general.c

index bf7afd1ec25b24c972a1db531a179e6a4f98a4ba..7ec80a84688446b8831edb30499de5bdf5f165d4 100644 (file)
@@ -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);