diff -r 550db5cefcc2 -r 8a2d1c2ceb88 src/saveload.cpp --- a/src/saveload.cpp Wed Jun 27 01:01:16 2007 +0000 +++ b/src/saveload.cpp Sat Jul 07 09:20:52 2007 +0000 @@ -17,7 +17,6 @@ #include "openttd.h" #include "debug.h" #include "functions.h" -#include "hal.h" #include "vehicle.h" #include "station.h" #include "thread.h" @@ -288,6 +287,8 @@ _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 +296,20 @@ 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; @@ -496,6 +496,7 @@ * @return return the net length of the string */ static inline size_t SlCalcNetStringLen(const char *ptr, size_t length) { + if (ptr == NULL) return 0; return minu(strlen(ptr), length - 1); } @@ -573,9 +574,13 @@ case SLE_VAR_STR: case SLE_VAR_STRQ: // Malloc'd string, free previous incarnation, and allocate free(*(char**)ptr); - *(char**)ptr = (char*)malloc(len + 1); // terminating '\0' - ptr = *(char**)ptr; - SlCopyBytes(ptr, len); + if (len == 0) { + *(char**)ptr = NULL; + } else { + *(char**)ptr = (char*)malloc(len + 1); // terminating '\0' + ptr = *(char**)ptr; + SlCopyBytes(ptr, len); + } break; } @@ -1599,6 +1604,8 @@ } 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