KeyValues: fix bug when loading from file

Read file as binary, and check if the file we're opening has a size.
This commit is contained in:
Kawe Mazidjatari 2024-01-12 03:08:31 +01:00
parent 6f11fffe63
commit 7cbb8a994d

View File

@ -1875,7 +1875,7 @@ bool KeyValues::LoadFromFile(IBaseFileSystem* filesystem, const char* resourceNa
{
//TM_ZONE_FILTERED( TELEMETRY_LEVEL0, 50, TMZF_NONE, "%s %s", __FUNCTION__, tmDynamicString( TELEMETRY_LEVEL0, resourceName ) );
FileHandle_t f = filesystem->Open(resourceName, "rt", pathID);
FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
if (!f)
return false;
@ -1883,6 +1883,10 @@ bool KeyValues::LoadFromFile(IBaseFileSystem* filesystem, const char* resourceNa
// load file into a null-terminated buffer
const ssize_t fileSize = filesystem->Size(f);
if (!fileSize)
return false;
std::unique_ptr<char[]> pBuf(new char[fileSize + 1]);
const ssize_t nRead = filesystem->Read(pBuf.get(), fileSize, f);