diff options
author | Torbjörn Andersson | 2007-06-16 19:27:05 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2007-06-16 19:27:05 +0000 |
commit | fe8a7163cdd39c292e46e9713b26c6e07bf7faf0 (patch) | |
tree | 7a4f0506f999c6ddb181904bcdc30c092f2963e1 /engines | |
parent | 276cdc54166cf002dfecba0e1417db3aa70eea19 (diff) | |
download | scummvm-rg350-fe8a7163cdd39c292e46e9713b26c6e07bf7faf0.tar.gz scummvm-rg350-fe8a7163cdd39c292e46e9713b26c6e07bf7faf0.tar.bz2 scummvm-rg350-fe8a7163cdd39c292e46e9713b26c6e07bf7faf0.zip |
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
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sword1/control.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
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; } |