From 866b3974fcb7297b2ee39312e579bb19df127ad5 Mon Sep 17 00:00:00 2001 From: Brodie Thiesfield Date: Wed, 15 Aug 2012 20:53:03 +0000 Subject: Ensure that the file buffer is always null terminated (thanks to irov13 for bug notification and patch) --- SimpleIni.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SimpleIni.h b/SimpleIni.h index b876479..39769d9 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -1355,10 +1355,15 @@ CSimpleIniTempl::LoadFile( if (lSize == 0) { return SI_OK; } - char * pData = new char[lSize]; + + // allocate and ensure NULL terminated + char * pData = new char[lSize+1]; if (!pData) { return SI_NOMEM; } + pData[lSize] = 0; + + // load data into buffer fseek(a_fpFile, 0, SEEK_SET); size_t uRead = fread(pData, sizeof(char), lSize, a_fpFile); if (uRead != (size_t) lSize) { -- cgit v1.2.3