summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-06-27 23:26:40 +0000
committerrubidium <rubidium@openttd.org>2007-06-27 23:26:40 +0000
commit4720ff0de30de4b9a61c01ce2001ff3a834e2c39 (patch)
tree721e689063a109128bc53e0765d0190424c12d9a /src
parent7eb0b004f35cee37219845ae50fb8eb712c23899 (diff)
downloadopenttd-4720ff0de30de4b9a61c01ce2001ff3a834e2c39.tar.xz
(svn r10367) -Fix: do not crash horribly when the file you are trying to load is too short or decompressing it fails.
Diffstat (limited to 'src')
-rw-r--r--src/saveload.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/saveload.cpp b/src/saveload.cpp
index 4fe005941..71417ea07 100644
--- a/src/saveload.cpp
+++ b/src/saveload.cpp
@@ -288,6 +288,8 @@ void SlSetArrayIndex(uint index)
_sl.array_index = index;
}
+static uint32 _next_offs;
+
/**
* Iterate through the elements of an array and read the whole thing
* @return The index of the object, or -1 if we have reached the end of current block
@@ -295,21 +297,20 @@ void SlSetArrayIndex(uint index)
int SlIterateArray()
{
int index;
- static uint32 next_offs;
/* After reading in the whole array inside the loop
* we must have read in all the data, so we must be at end of current block. */
- assert(next_offs == 0 || SlGetOffs() == next_offs);
+ if (_next_offs != 0 && SlGetOffs() != _next_offs) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, "Invalid chunk size");
while (true) {
uint length = SlReadArrayLength();
if (length == 0) {
- next_offs = 0;
+ _next_offs = 0;
return -1;
}
_sl.obj_len = --length;
- next_offs = SlGetOffs() + length;
+ _next_offs = SlGetOffs() + length;
switch (_sl.block_mode) {
case CH_SPARSE_ARRAY: index = (int)SlReadSparseIndex(); break;
@@ -1599,6 +1600,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
}
WaitTillSaved();
+ _next_offs = 0;
+
/* Load a TTDLX or TTDPatch game */
if (mode == SL_OLD_LOAD) {
InitializeGame(IG_DATE_RESET, 256, 256); // set a mapsize of 256x256 for TTDPatch games or it might get confused