Try to be more robust/paranoid when reading the SAVEGAME.INF file. Apart from

being a sensible precaution, it should work around some bugs like #1737801,
where the file is obviously corrupted. (Possibly mutilated by some file
transfer program.)

svn-id: r27484
This commit is contained in:
Torbjörn Andersson 2007-06-16 19:27:05 +00:00
parent 276cdc5416
commit fe8a7163cd

View File

@ -700,6 +700,9 @@ void Control::readSavegameDescriptions(void) {
inf = _saveFileMan->openForLoading("SAVEGAME.INF");
_saveScrollPos = _saveFiles = 0;
_selectedSavegame = 255;
for (uint8 cnt = 0; cnt < 64; cnt++) {
memset(_saveNames[cnt], 0, sizeof(_saveNames[cnt]));
}
if (inf) {
uint8 curFileNum = 0;
uint8 ch;
@ -707,20 +710,18 @@ void Control::readSavegameDescriptions(void) {
uint8 pos = 0;
do {
ch = inf->readByte();
if ((ch == 10) || (ch == 255))
_saveNames[curFileNum][pos] = '\0';
else
_saveNames[curFileNum][pos] = ch;
pos++;
} while ((ch != 10) && (ch != 255));
curFileNum++;
} while (ch != 255);
if (pos < sizeof(_saveNames[curFileNum]) - 1) {
if ((ch == 10) || (ch == 255) || (inf->eos()))
_saveNames[curFileNum][pos++] = '\0';
else if (ch >= 32)
_saveNames[curFileNum][pos++] = ch;
}
} while ((ch != 10) && (ch != 255) && (!inf->eos()));
if (_saveNames[curFileNum][0] != 0)
curFileNum++;
} while ((ch != 255) && (!inf->eos()));
_saveFiles = curFileNum;
for (uint8 cnt = _saveFiles; cnt < 64; cnt++)
_saveNames[cnt][0] = '\0';
} else
for (uint8 cnt = 0; cnt < 64; cnt++)
_saveNames[cnt][0] = '\0';
}
delete inf;
}