From 482f835ad6c1260fb2fc2609ecca70f3ac618fc5 Mon Sep 17 00:00:00 2001 From: D G Turner Date: Sun, 25 Aug 2019 05:55:54 +0100 Subject: AGI: Fix GCC Compiler Warnings from memset of Game State Structures This fixes these, but adding constructors causes further memset usage warnings on the structures which are now "non-trivial" due to the addition of constructors. Should be able to fix by repeating this process to remove further memset usage. --- engines/agi/agi.cpp | 1 - engines/agi/agi.h | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ engines/agi/logic.h | 2 + engines/agi/picture.h | 2 + engines/agi/preagi.cpp | 1 - engines/agi/view.h | 8 ++++ 6 files changed, 111 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp index 93e1187523..227700561b 100644 --- a/engines/agi/agi.cpp +++ b/engines/agi/agi.cpp @@ -360,7 +360,6 @@ AgiEngine::AgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : AgiBas DebugMan.addDebugChannel(kDebugLevelText, "Text", "Text output debugging"); DebugMan.addDebugChannel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging"); - memset(&_game, 0, sizeof(struct AgiGame)); memset(&_debug, 0, sizeof(struct AgiDebug)); _game.mouseEnabled = true; diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 71ba8e9298..8627d2d8b1 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -353,6 +353,8 @@ enum { struct AgiControllerKeyMapping { uint16 keycode; byte controllerSlot; + + AgiControllerKeyMapping() : keycode(0), controllerSlot(0) {} }; struct AgiObject { @@ -372,12 +374,16 @@ struct AgiDir { // 3 = in mem, cant be released // 0x40 = was compressed uint8 flags; + + AgiDir() : volume(0), offset(0), len(0), clen(0), flags(0) {} }; struct AgiBlock { bool active; int16 x1, y1; int16 x2, y2; + + AgiBlock() : active(false), x1(0), y1(0), x2(0), y2(0) {} }; struct ScriptPos { @@ -493,6 +499,99 @@ struct AgiGame { int16 nonBlockingTextCyclesLeft; bool automaticRestoreGame; + + AgiGame() { + _vm = nullptr; + + adjMouseX = 0; + adjMouseY = 0; + + for (uint16 i = 0; i < ARRAYSIZE(name); i++) { + name[i] = 0; + } + for (uint16 i = 0; i < ARRAYSIZE(id); i++) { + id[i] = 0; + } + crc = 0; + + for (uint16 i = 0; i < ARRAYSIZE(flags); i++) { + flags[i] = 0; + } + for (uint16 i = 0; i < ARRAYSIZE(vars); i++) { + vars[i] = 0; + } + + horizon = 0; + + cycleInnerLoopActive = false; + cycleInnerLoopType = 0; + + curLogicNr = 0; + + // execStack is defaulted by Common::Array constructor + + playerControl = false; + exitAllLogics = false; + pictureShown = false; + gameFlags = 0; + + // block defaulted by AgiBlock constructor + + gfxMode = false; + + numObjects = 0; + + for (uint16 i = 0; i < ARRAYSIZE(controllerOccured); i++) { + controllerOccured[i] = false; + } + + // controllerKeyMapping defaulted by AgiControllerKeyMapping constructor + + for (uint16 i = 0; i < MAX_STRINGS + 1; i++) { + for (uint16 j = 0; j < MAX_STRINGLEN; j++) { + strings[i][j] = 0; + } + } + + // dirLogic cleared by AgiDir constructor + // dirPic cleared by AgiDir constructor + // dirView cleared by AgiDir constructor + // dirSound cleared by AgiDir constructor + + // pictures cleared by AgiPicture constructor + // logics cleared by AgiLogic constructor + // views cleared by AgiView constructor + for (uint16 i = 0; i < ARRAYSIZE(sounds); i++) { + sounds[i] = nullptr; + } + + _curLogic = nullptr; + + // screenObjTable cleared by ScreenObjEntry constructor + + // addToPicView cleared by ScreenObjEntry constructor + + automaticSave = false; + for (uint16 i = 0; i < ARRAYSIZE(automaticSaveDescription); i++) { + automaticSaveDescription[i] = 0; + } + + // mouseFence cleared by Common::Rect constructor + mouseEnabled = false; + mouseHidden = false; + + testResult = 0; + + max_logics = 0; + for (uint16 i = 0; i < ARRAYSIZE(logic_list); i++) { + logic_list[i] = 0; + } + + nonBlockingTextShown = false; + nonBlockingTextCyclesLeft = 0; + + automaticRestoreGame = false; + } }; class AgiLoader { diff --git a/engines/agi/logic.h b/engines/agi/logic.h index b46362056f..5e8700d9a8 100644 --- a/engines/agi/logic.h +++ b/engines/agi/logic.h @@ -35,6 +35,8 @@ struct AgiLogic { int cIP; /**< current IP */ int numTexts; /**< number of messages */ const char **texts; /**< message list */ + + AgiLogic() : data(nullptr), size(0), sIP(0), cIP(0), numTexts(0), texts(nullptr) {} }; } // End of namespace Agi diff --git a/engines/agi/picture.h b/engines/agi/picture.h index 2cb5bfabc8..1380aae3fc 100644 --- a/engines/agi/picture.h +++ b/engines/agi/picture.h @@ -34,6 +34,8 @@ namespace Agi { struct AgiPicture { uint32 flen; /**< size of raw data */ uint8 *rdata; /**< raw vector image data */ + + AgiPicture() : flen(0), rdata(nullptr) {} }; // AGI picture version diff --git a/engines/agi/preagi.cpp b/engines/agi/preagi.cpp index 6262ee931f..e2751cd87b 100644 --- a/engines/agi/preagi.cpp +++ b/engines/agi/preagi.cpp @@ -48,7 +48,6 @@ PreAgiEngine::PreAgiEngine(OSystem *syst, const AGIGameDescription *gameDesc) : DebugMan.addDebugChannel(kDebugLevelText, "Text", "Text output debugging"); DebugMan.addDebugChannel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging"); - memset(&_game, 0, sizeof(struct AgiGame)); memset(&_debug, 0, sizeof(struct AgiDebug)); _speakerHandle = new Audio::SoundHandle(); diff --git a/engines/agi/view.h b/engines/agi/view.h index 1c57d5d468..e4adfdc014 100644 --- a/engines/agi/view.h +++ b/engines/agi/view.h @@ -47,6 +47,14 @@ struct AgiView { byte *description; int16 loopCount; AgiViewLoop *loop; + + AgiView() { + headerStepSize = 0; + headerCycleTime = 0; + description = nullptr; + loopCount = 0; + loop = nullptr; + } }; enum MotionType { -- cgit v1.2.3