mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-02-03 04:05:49 +01:00
FileStream::Read: Throw the exception basing on fread return value
This change removes ftell/GetPosition() from hot spots during the startup, "optimizing" the function for success cases - reading past EOF should never/rarely happen so it seems fine to let it try to read before checking
This commit is contained in:
@@ -165,13 +165,9 @@ namespace OpenRCT2
|
||||
|
||||
void FileStream::Read(void* buffer, uint64_t length)
|
||||
{
|
||||
uint64_t remainingBytes = GetLength() - GetPosition();
|
||||
if (length <= remainingBytes)
|
||||
if (fread(buffer, 1, static_cast<size_t>(length), _file) == length)
|
||||
{
|
||||
if (fread(buffer, static_cast<size_t>(length), 1, _file) == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw IOException("Attempted to read past end of file.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user