--Bug fixes

-Another attempt to fix null termination bug with reading files for Xml processing.
This commit is contained in:
Person 2024-03-08 10:14:21 -07:00
parent 9a56f286b2
commit 26e075def5

View File

@ -332,12 +332,12 @@ static bool ReadFile(const char* filename, string& buf, bool nullTerminate = tru
if (const auto pos = ifs.tellg())//Ensure it exists and wasn't empty. if (const auto pos = ifs.tellg())//Ensure it exists and wasn't empty.
{ {
buf.resize(pos + streampos(nullTerminate ? 1 : 0)); buf.resize(pos);// +streampos(nullTerminate ? 1 : 0));
ifs.seekg(0, ios::beg); ifs.seekg(0, ios::beg);
ifs.read(&buf[0], pos); ifs.read(&buf[0], pos);
if (nullTerminate && (buf[buf.size() - 1] != 0))//Optionally NULL terminate if they want to treat it as a string, and it's not terminated arleady. if (nullTerminate && (buf[buf.size() - 1] != 0))//Optionally NULL terminate if they want to treat it as a string, and it's not terminated arleady.
buf[buf.size() - 1] = 0; buf.push_back(0);
return true; return true;
} }