aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Winston2024-05-23 21:19:20 -0400
committerBen Winston2024-05-23 21:19:20 -0400
commit177e0bff0df05c57f00d58a55baba4aa8e0661ec (patch)
treef3514932289b0aa0b11ae2c813d9577ca018f645
parentfe8a8e660c28c8d61be71597cdafef850209e9cb (diff)
bugfix: trailing null byte in data from file
-rw-r--r--booki.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/booki.c b/booki.c
index afca7ed..a90edeb 100644
--- a/booki.c
+++ b/booki.c
@@ -285,7 +285,7 @@ char* load_file(char* filename) {
int size = ftell(fp);
rewind(fp);
- char* data = malloc(size);
+ char* data = malloc(size + 1);
if (!data) {
printf("couldn't malloc\n");
return NULL;
@@ -297,6 +297,7 @@ char* load_file(char* filename) {
return NULL;
}
+ data[size] = '\0';
fclose(fp);
return data;