diff options
author | Brodie Thiesfield <brofield@gmail.com> | 2012-08-16 00:53:03 +0400 |
---|---|---|
committer | Brodie Thiesfield <brofield@gmail.com> | 2012-08-16 00:53:03 +0400 |
commit | 866b3974fcb7297b2ee39312e579bb19df127ad5 (patch) | |
tree | 43a28612b4c6778faff004abf33f82615cbc4974 | |
parent | b0527ae8ecf59867903bf39ca8ebe5a590269f35 (diff) |
Ensure that the file buffer is always null terminated (thanks to irov13 for bug notification and patch)
-rw-r--r-- | SimpleIni.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/SimpleIni.h b/SimpleIni.h index b876479..39769d9 100644 --- a/SimpleIni.h +++ b/SimpleIni.h @@ -1355,10 +1355,15 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::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) { |