fix slurp(), it needs to read size-1 for the trailing NUL

This commit is contained in:
Michael Stapelberg 2013-11-09 14:12:22 +01:00
parent ebfafc5dac
commit 31509b0d56

View 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);