From 86320c9cb74b07e6747b9b2ff986385bba9fd6c8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 5 Jul 2019 16:49:36 +0200 Subject: load_entire_file(): Ensure string termination --- libcrystfel/src/detector.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libcrystfel') 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); -- cgit v1.2.3