From fe8a7163cdd39c292e46e9713b26c6e07bf7faf0 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 16 Jun 2007 19:27:05 +0000 Subject: 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 --- engines/sword1/control.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'engines/sword1') diff --git a/engines/sword1/control.cpp b/engines/sword1/control.cpp index e40db20f37..63b86997ce 100644 --- a/engines/sword1/control.cpp +++ b/engines/sword1/control.cpp @@ -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; } -- cgit v1.2.3