From 71a703d8bb09cd6e520c40d8db1576687e888292 Mon Sep 17 00:00:00 2001 From: Littleboy Date: Wed, 11 Jun 2014 20:55:31 -0400 Subject: LASTEXPRESS: Update SavePoint::push/call interface and check for string size. CID 1003261, 1003262 --- engines/lastexpress/game/action.cpp | 2 +- engines/lastexpress/game/savepoint.cpp | 16 +++++++++------- engines/lastexpress/game/savepoint.h | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'engines/lastexpress/game') diff --git a/engines/lastexpress/game/action.cpp b/engines/lastexpress/game/action.cpp index 986c56cb1b..96b97db939 100644 --- a/engines/lastexpress/game/action.cpp +++ b/engines/lastexpress/game/action.cpp @@ -1456,7 +1456,7 @@ IMPLEMENT_ACTION(playMusicChapterSetupTrain) if (!getSoundQueue()->isBuffered(filename) && hotspot.param3 & id) { getSound()->playSound(kEntityPlayer, filename, kFlagDefault); - getSavePoints()->call(kEntityPlayer, kEntityTrain, kAction203863200, filename.c_str()); + getSavePoints()->call(kEntityPlayer, kEntityTrain, kAction203863200, filename); getSavePoints()->push(kEntityPlayer, kEntityTrain, kAction222746496, hotspot.param2); } diff --git a/engines/lastexpress/game/savepoint.cpp b/engines/lastexpress/game/savepoint.cpp index b0186a4ccc..a8483e6d5c 100644 --- a/engines/lastexpress/game/savepoint.cpp +++ b/engines/lastexpress/game/savepoint.cpp @@ -28,7 +28,6 @@ #include "lastexpress/lastexpress.h" - namespace LastExpress { SavePoints::SavePoints(LastExpressEngine *engine) : _engine(engine) { @@ -57,7 +56,7 @@ void SavePoints::push(EntityIndex entity2, EntityIndex entity1, ActionIndex acti _savepoints.push_back(point); } -void SavePoints::push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const char *param) { +void SavePoints::push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const Common::String param) { if (_savepoints.size() >= _savePointsMaxSize) return; @@ -65,7 +64,9 @@ void SavePoints::push(EntityIndex entity2, EntityIndex entity1, ActionIndex acti point.entity1 = entity1; point.action = action; point.entity2 = entity2; - strcpy((char *)&point.param.charValue, param); + + assert(param.size() <= 5); + strncpy((char *)&point.param.charValue, param.c_str(), 5); _savepoints.push_back(point); } @@ -76,7 +77,6 @@ SavePoint SavePoints::pop() { return point; } - void SavePoints::pushAll(EntityIndex entity, ActionIndex action, uint32 param) { for (uint32 index = 1; index < 40; index++) { if ((EntityIndex)index != entity) @@ -156,16 +156,18 @@ void SavePoints::call(EntityIndex entity2, EntityIndex entity1, ActionIndex acti } } -void SavePoints::call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const char *param) const { +void SavePoints::call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const Common::String param) const { SavePoint point; point.entity1 = entity1; point.action = action; point.entity2 = entity2; - strcpy((char *)&point.param.charValue, param); + + assert(param.size() <= 5); + strncpy((char *)&point.param.charValue, param.c_str(), 5); Callback *callback = getCallback(entity1); if (callback != NULL && callback->isValid()) { - debugC(8, kLastExpressDebugLogic, "Savepoint: entity1=%s, action=%s, entity2=%s, param=%s", ENTITY_NAME(entity1), ACTION_NAME(action), ENTITY_NAME(entity2), param); + debugC(8, kLastExpressDebugLogic, "Savepoint: entity1=%s, action=%s, entity2=%s, param=%s", ENTITY_NAME(entity1), ACTION_NAME(action), ENTITY_NAME(entity2), param.c_str()); (*callback)(point); } } diff --git a/engines/lastexpress/game/savepoint.h b/engines/lastexpress/game/savepoint.h index 068c54eb0f..ab6490796b 100644 --- a/engines/lastexpress/game/savepoint.h +++ b/engines/lastexpress/game/savepoint.h @@ -101,7 +101,7 @@ public: // Savepoints void push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, uint32 param = 0); - void push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const char *param); + void push(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const Common::String param); void pushAll(EntityIndex entity, ActionIndex action, uint32 param = 0); void process(); void reset(); @@ -113,7 +113,7 @@ public: void setCallback(EntityIndex index, Callback *callback); Callback *getCallback(EntityIndex entity) const; void call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, uint32 param = 0) const; - void call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const char *param) const; + void call(EntityIndex entity2, EntityIndex entity1, ActionIndex action, const Common::String param) const; void callAndProcess(); // Serializable -- cgit v1.2.3