aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLittleboy2012-08-27 21:49:15 -0400
committerLittleboy2012-08-27 21:49:43 -0400
commitee8581b778b83bc01af0f26bc8b3680ebc266700 (patch)
tree5f428d33de4edb4e3fb10d6a70836b4f259a98ba
parent6ab3b903d46899d642fb57faad6b445242285033 (diff)
downloadscummvm-rg350-ee8581b778b83bc01af0f26bc8b3680ebc266700.tar.gz
scummvm-rg350-ee8581b778b83bc01af0f26bc8b3680ebc266700.tar.bz2
scummvm-rg350-ee8581b778b83bc01af0f26bc8b3680ebc266700.zip
LASTEXPRESS: Cleanup savegame
- Check for valid stream in readValue/writeValue functions - Properly initialize/clear members
-rw-r--r--engines/lastexpress/game/savegame.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/engines/lastexpress/game/savegame.cpp b/engines/lastexpress/game/savegame.cpp
index 9857ef24cc..7efce0007b 100644
--- a/engines/lastexpress/game/savegame.cpp
+++ b/engines/lastexpress/game/savegame.cpp
@@ -78,7 +78,7 @@ uint32 SavegameStream::read(void *dataPtr, uint32 dataSize) {
uint32 SavegameStream::readUncompressed(void *dataPtr, uint32 dataSize) {
if ((int32)dataSize > size() - pos()) {
- dataSize = size() - pos();
+ dataSize = (uint32)(size() - pos());
_eos = true;
}
memcpy(dataPtr, getData() + pos(), dataSize);
@@ -230,7 +230,7 @@ uint32 SavegameStream::writeCompressed(const void *dataPtr, uint32 dataSize) {
if (*data != _previousValue || _repeatCount >= 255) {
if (_previousValue) {
writeBuffer(0xFF, true);
- writeBuffer(_repeatCount, true);
+ writeBuffer((uint8)_repeatCount, true);
writeBuffer(_previousValue, true);
_previousValue = *data++;
@@ -255,7 +255,7 @@ uint32 SavegameStream::writeCompressed(const void *dataPtr, uint32 dataSize) {
}
writeBuffer(0xFD, true);
- writeBuffer(_repeatCount, true);
+ writeBuffer((uint8)_repeatCount, true);
_previousValue = *data++;
_valueCount = 1;
@@ -348,11 +348,12 @@ uint32 SavegameStream::readCompressed(void *dataPtr, uint32 dataSize) {
// Constructors
//////////////////////////////////////////////////////////////////////////
-SaveLoad::SaveLoad(LastExpressEngine *engine) : _engine(engine), _savegame(NULL), _gameTicksLastSavegame(0) {
+SaveLoad::SaveLoad(LastExpressEngine *engine) : _engine(engine), _savegame(NULL), _gameTicksLastSavegame(0), _entity(kEntityPlayer) {
}
SaveLoad::~SaveLoad() {
clear(true);
+ _savegame = NULL;
// Zero passed pointers
_engine = NULL;
@@ -634,6 +635,9 @@ bool SaveLoad::loadMainHeader(Common::InSaveFile *stream, SavegameMainHeader *he
// Entries
//////////////////////////////////////////////////////////////////////////
uint32 SaveLoad::writeValue(Common::Serializer &ser, const char *name, Common::Functor1<Common::Serializer &, void> *function, uint size) {
+ if (!_savegame)
+ error("[SaveLoad::writeValue] Stream not initialized properly");
+
debugC(kLastExpressDebugSavegame, "Savegame: Writing %s: %u bytes", name, size);
uint32 prevPosition = (uint32)_savegame->pos();
@@ -652,6 +656,9 @@ uint32 SaveLoad::writeValue(Common::Serializer &ser, const char *name, Common::F
}
uint32 SaveLoad::readValue(Common::Serializer &ser, const char *name, Common::Functor1<Common::Serializer &, void> *function, uint size) {
+ if (!_savegame)
+ error("[SaveLoad::readValue] Stream not initialized properly");
+
debugC(kLastExpressDebugSavegame, "Savegame: Reading %s: %u bytes", name, size);
uint32 prevPosition = (uint32)_savegame->pos();