aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-10-06 16:47:13 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-10-06 16:47:13 +0200
commit631b6c7c826477ebc3b8b59a2a77df8592e0c627 (patch)
tree15bdbc77e2ff9d28fcb5d5e219244b56ef580d56
parentf56755cffd420ce44f6fac519bc7b857a5d06410 (diff)
downloadmblaze-631b6c7c826477ebc3b8b59a2a77df8592e0c627.tar.gz
slurp: zero-terminate buffer
-rw-r--r--slurp.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/slurp.c b/slurp.c
index 6366e6f..388f203 100644
--- a/slurp.c
+++ b/slurp.c
@@ -29,7 +29,7 @@ slurp(char *filename, char **bufo, off_t *leno)
*leno = 0;
return 0;
}
- *bufo = malloc(st.st_size);
+ *bufo = malloc(st.st_size + 1);
if (!*bufo) {
r = ENOMEM;
goto out;
@@ -48,7 +48,9 @@ slurp(char *filename, char **bufo, off_t *leno)
break;
nread += n;
} while (nread < st.st_size);
+
*leno = nread;
+ (*bufo)[st.st_size] = 0;
out:
close(fd);