From 3adbc1a261ce861271ae7d643eacdf93a7036659 Mon Sep 17 00:00:00 2001 From: martamoreton Date: Wed, 26 Apr 2017 12:37:12 +0200 Subject: [PATCH] Reserve space for the c-string null termination Reserve space for the c-string null termination --- src/http_utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/http_utils.cpp b/src/http_utils.cpp index d5cd8ef9..e61d425b 100644 --- a/src/http_utils.cpp +++ b/src/http_utils.cpp @@ -485,9 +485,10 @@ size_t load_file (const char* filename, char** content) if(fp.is_open()) { int size = fp.tellg(); - *content = (char*) malloc(size * sizeof(char)); + *content = (char*) malloc((size+1) * sizeof(char)); fp.seekg(0, ios::beg); fp.read(*content, size); + content[size] = '\0'; fp.close(); return size; }