aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-07-05 16:49:36 +0200
committerThomas White <taw@physics.org>2019-07-05 16:49:36 +0200
commit86320c9cb74b07e6747b9b2ff986385bba9fd6c8 (patch)
tree7c93583022ce0b7887a1eae24e986f859df973a4
parent201c66f8c61cdfbdf2b54c3e6f452a4d6cc80c03 (diff)
load_entire_file(): Ensure string termination
-rw-r--r--libcrystfel/src/detector.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c
index bd0c94f1..fd04beaf 100644
--- a/libcrystfel/src/detector.c
+++ b/libcrystfel/src/detector.c
@@ -1718,7 +1718,7 @@ char *load_entire_file(const char *filename)
return NULL;
}
- contents = malloc(statbuf.st_size);
+ contents = malloc(statbuf.st_size+1);
if ( contents == NULL ) {
ERROR("Failed to allocate memory for file\n");
return NULL;
@@ -1736,6 +1736,7 @@ char *load_entire_file(const char *filename)
free(contents);
return NULL;
}
+ contents[statbuf.st_size] = '\0';
fclose(fh);