BACKENDS: Fix undefined parsing of timestamps file

DefaultSaveFileManager::loadTimestamps() was parsing strings from the
timestamps file by checking for end-of-stream after using the byte it
attempted to read. This worked because ReadStream::readByte() returns 0
on error, but that's undefined behavior with a FIXME to remove.

This bug was exposed by the recently added warning when 0 is appended
to a String: ab06f27d43
This commit is contained in:
sluicebox 2021-06-29 13:29:43 -05:00
parent 8f60095c89
commit 9987cc4c5b

View File

@ -309,8 +309,9 @@ Common::HashMap<Common::String, uint32> DefaultSaveFileManager::loadTimestamps()
while (!file->eos()) {
//read filename into buffer (reading until the first ' ')
Common::String buffer;
while (!file->eos()) {
while (true) {
byte b = file->readByte();
if (file->eos()) break;
if (b == ' ') break;
buffer += (char)b;
}
@ -320,8 +321,9 @@ Common::HashMap<Common::String, uint32> DefaultSaveFileManager::loadTimestamps()
while (true) {
bool lineEnded = false;
buffer = "";
while (!file->eos()) {
while (true) {
byte b = file->readByte();
if (file->eos()) break;
if (b == ' ' || b == '\n' || b == '\r') {
lineEnded = (b == '\n');
break;