From 805fb7699df246a608fae602d2a508983d94d52e Mon Sep 17 00:00:00 2001 From: Paul Kitchen Date: Tue, 5 Jun 2018 08:19:41 -0600 Subject: [PATCH] Reserve extra byte in LoadDataFromFile() in case caller wants to append '\0' --- src/ccutil/genericvector.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ccutil/genericvector.h b/src/ccutil/genericvector.h index 73e5f6099..22bd3cc28 100644 --- a/src/ccutil/genericvector.h +++ b/src/ccutil/genericvector.h @@ -375,6 +375,8 @@ inline bool LoadDataFromFile(const char* filename, GenericVector* data) { fseek(fp, 0, SEEK_SET); // Trying to open a directory on Linux sets size to LONG_MAX. Catch it here. if (size > 0 && size < LONG_MAX) { + // reserve an extra byte in case caller wants to append a '\0' character + data->reserve(size + 1); data->resize_no_init(size); result = static_cast(fread(&(*data)[0], 1, size, fp)) == size; }