[Scummvm-git-logs] scummvm master -> 7a77af7160e6d9ab5a361f1ab76acd78dc1bcbf8

mduggan noreply at scummvm.org
Mon Jul 1 09:33:06 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
7a77af7160 DGDS: Fix many small issues identified by Coverity


Commit: 7a77af7160e6d9ab5a361f1ab76acd78dc1bcbf8
    https://github.com/scummvm/scummvm/commit/7a77af7160e6d9ab5a361f1ab76acd78dc1bcbf8
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2024-07-01T19:32:57+10:00

Commit Message:
DGDS: Fix many small issues identified by Coverity

Changed paths:
    engines/dgds/ads.cpp
    engines/dgds/decompress.cpp
    engines/dgds/decompress.h
    engines/dgds/dgds.cpp
    engines/dgds/font.cpp
    engines/dgds/inventory.cpp
    engines/dgds/menu.cpp
    engines/dgds/music.cpp
    engines/dgds/request.cpp
    engines/dgds/resource.h
    engines/dgds/scene.cpp
    engines/dgds/scene.h
    engines/dgds/ttm.cpp


diff --git a/engines/dgds/ads.cpp b/engines/dgds/ads.cpp
index aa751f55638..c9335084c29 100644
--- a/engines/dgds/ads.cpp
+++ b/engines/dgds/ads.cpp
@@ -322,6 +322,9 @@ bool ADSInterpreter::logicOpResult(uint16 code, const TTMEnviro *env, const TTMS
 	int16 envNum = env ? env->_enviro : 0;
 	int16 seqNum = seq ? seq->_seqNum : 0;
 	const char *optype = (code < 0x1300 ? "while" : "if");
+
+	assert (seq || code == 0x1380 || code == 0x1390);
+
 	switch (code) {
 	case 0x1010: // WHILE runtype 5
 	case 0x1310: // IF runtype 5, 2 params
@@ -680,7 +683,7 @@ bool ADSInterpreter::handleOperation(uint16 code, Common::SeekableReadStream *sc
 		int16 segment = scr->readSint16LE();
 		int16 idx = getArrIndexOfSegNum(segment);
 		debug(10, "ADS 0x%04x: add 4 remove 8 to state seg %d idx %d", code, segment, idx);
-		if (segment >= 0) {
+		if (segment >= 0 && idx >= 0) {
 			int state = (_adsData->_state[idx] & 8) | 4;
 			_adsData->_state[idx] = state;
 		}
@@ -691,7 +694,7 @@ bool ADSInterpreter::handleOperation(uint16 code, Common::SeekableReadStream *sc
 		int16 segment = scr->readSint16LE();
 		int16 idx = getArrIndexOfSegNum(segment);
 		debug(10, "ADS 0x%04x: add 3 remove 8 to state seg %d idx %d", code, segment, idx);
-		if (segment >= 0) {
+		if (segment >= 0 && idx >= 0) {
 			int state = (_adsData->_state[idx] & 8) | 3;
 			_adsData->_state[idx] = state;
 		}
diff --git a/engines/dgds/decompress.cpp b/engines/dgds/decompress.cpp
index a9653921da3..2c71d7910ac 100644
--- a/engines/dgds/decompress.cpp
+++ b/engines/dgds/decompress.cpp
@@ -58,6 +58,10 @@ uint32 RleDecompressor::decompress(byte *dest, uint32 sz, Common::SeekableReadSt
 	return sz - left;
 }
 
+LzwDecompressor::LzwDecompressor() {
+	reset();
+}
+
 void LzwDecompressor::reset() {
 	memset(&_codeTable, 0, sizeof(_codeTable));
 
diff --git a/engines/dgds/decompress.h b/engines/dgds/decompress.h
index e6c24cfc42e..9d5e9c65fbb 100644
--- a/engines/dgds/decompress.h
+++ b/engines/dgds/decompress.h
@@ -38,6 +38,7 @@ public:
 
 class LzwDecompressor {
 public:
+	LzwDecompressor();
 	uint32 decompress(byte *dest, uint32 sz, Common::SeekableReadStream &input);
 
 protected:
diff --git a/engines/dgds/dgds.cpp b/engines/dgds/dgds.cpp
index 0529ce48ec5..2d02777f354 100644
--- a/engines/dgds/dgds.cpp
+++ b/engines/dgds/dgds.cpp
@@ -80,7 +80,7 @@ DgdsEngine::DgdsEngine(OSystem *syst, const ADGameDescription *gameDesc)
 	_gdsScene(nullptr), _resource(nullptr), _gamePals(nullptr), _gameGlobals(nullptr),
 	_detailLevel(kDgdsDetailHigh), _textSpeed(1), _justChangedScene1(false), _justChangedScene2(false),
 	_random("dgds"), _currentCursor(-1), _menuToTrigger(kMenuNone), _isLoading(true),
-	_rstFileName(nullptr), _difficulty(1) {
+	_rstFileName(nullptr), _difficulty(1), _menu(nullptr), _adsInterp(nullptr) {
 	syncSoundSettings();
 
 	_platform = gameDesc->platform;
diff --git a/engines/dgds/font.cpp b/engines/dgds/font.cpp
index 2f4990720ea..9e6349735ba 100644
--- a/engines/dgds/font.cpp
+++ b/engines/dgds/font.cpp
@@ -77,7 +77,6 @@ bool DgdsFont::hasChar(byte chr) const {
 }
 
 static inline bool isSet(const byte *data, uint bit) {
-	assert(bit >= 0);
 	return data[bit / 8] & (1 << (7 - (bit % 8)));
 }
 
diff --git a/engines/dgds/inventory.cpp b/engines/dgds/inventory.cpp
index befbbb29ace..e95b0e6fbe0 100644
--- a/engines/dgds/inventory.cpp
+++ b/engines/dgds/inventory.cpp
@@ -32,8 +32,9 @@ namespace Dgds {
 
 Inventory::Inventory() : _isOpen(false), _prevPageBtn(nullptr), _nextPageBtn(nullptr),
 	_invClock(nullptr), _itemZoomBox(nullptr), _exitButton(nullptr), _clockSkipMinBtn(nullptr),
-	_itemArea(nullptr), _clockSkipHrBtn(nullptr), _dropBtn(nullptr), _highlightItemNo(-1),
-	_itemOffset(0), _openedFromSceneNum(0), _showZoomBox(false), _fullWidth(-1)
+	_itemArea(nullptr), _clockSkipHrBtn(nullptr), _dropBtn(nullptr), _itemBox(nullptr),
+	_highlightItemNo(-1), _itemOffset(0), _openedFromSceneNum(0), _showZoomBox(false),
+	_fullWidth(-1)
 {
 }
 
diff --git a/engines/dgds/menu.cpp b/engines/dgds/menu.cpp
index 01da6240232..36b2104b978 100644
--- a/engines/dgds/menu.cpp
+++ b/engines/dgds/menu.cpp
@@ -131,14 +131,17 @@ void Menu::configureGadget(MenuId menu, Gadget* gadget) {
 		SliderGadget *slider = dynamic_cast<SliderGadget *>(gadget);
 		switch (gadget->_gadgetNo) {
 		case kMenuSliderControlsDifficulty:
+			assert(slider);
 			slider->setSteps(3, false);
 			slider->setValue(engine->getDifficulty()); // TODO: set a difficulty value
 			break;
 		case kMenuSliderControlsTextSpeed:
+			assert(slider);
 			slider->setSteps(10, false);
 			slider->setValue(9 - engine->getTextSpeed());
 			break;
 		case kMenuSliderControlsDetailLevel:
+			assert(slider);
 			slider->setSteps(2, true);
 			slider->setValue(engine->getDetailLevel());
 			break;
diff --git a/engines/dgds/music.cpp b/engines/dgds/music.cpp
index 8d50261aceb..e0b318d5f4d 100644
--- a/engines/dgds/music.cpp
+++ b/engines/dgds/music.cpp
@@ -59,6 +59,7 @@ public:
 
 MidiParser_DGDS::MidiParser_DGDS() : _init(nullptr), _last(nullptr), _numParts(0) {
 	memset(_trackSz, 0, sizeof(_trackSz));
+	memset(_trackPtr, 0, sizeof(_trackPtr));
 }
 
 MidiParser_DGDS::~MidiParser_DGDS() {
diff --git a/engines/dgds/request.cpp b/engines/dgds/request.cpp
index 2aab07634a5..4c7cc87e8fa 100644
--- a/engines/dgds/request.cpp
+++ b/engines/dgds/request.cpp
@@ -478,7 +478,7 @@ void SliderGadget::draw(Graphics::ManagedSurface *dst) const {
 }
 
 SliderGadget::SliderGadget() : _lock(false), _steps(0), _gadget2_i1(0),
-	_gadget2_i2(0), _gadget2_i3(0), _gadget2_i4(0) {
+	_gadget2_i2(0), _gadget2_i3(0), _gadget2_i4(0), _handleX(0) {
 }
 
 int16 SliderGadget::getHandleWidth() const {
@@ -759,8 +759,7 @@ void RequestData::drawBackgroundNoSliders(Graphics::ManagedSurface *dst, const C
 
 /*static*/
 void RequestData::fillBackground(Graphics::ManagedSurface *dst, uint16 x, uint16 y, uint16 width, uint16 height, int16 startoffset) {
-	bool detailHigh = true;
-	if (detailHigh) {
+	if (static_cast<DgdsEngine *>(g_engine)->getDetailLevel() == kDgdsDetailHigh) {
 		Graphics::Surface area = dst->getSubArea(Common::Rect(x, y, x + width, y + height));
 		while (startoffset < 0)
 			startoffset += ARRAYSIZE(MenuBackgroundColors);
diff --git a/engines/dgds/resource.h b/engines/dgds/resource.h
index ea6c0a20f9a..9099ce85746 100644
--- a/engines/dgds/resource.h
+++ b/engines/dgds/resource.h
@@ -65,7 +65,7 @@ private:
 
 class DgdsChunkReader {
 public:
-	DgdsChunkReader(Common::SeekableReadStream *stream) : _sourceStream(stream), _contentStream(nullptr), _size(0), _container(false), _startPos(0) {}
+	DgdsChunkReader(Common::SeekableReadStream *stream) : _sourceStream(stream), _contentStream(nullptr), _size(0), _container(false), _startPos(0), _id(0) {}
 	~DgdsChunkReader();
 
 	bool isSection(const Common::String &section) const;
diff --git a/engines/dgds/scene.cpp b/engines/dgds/scene.cpp
index 89269597440..6b35f855249 100644
--- a/engines/dgds/scene.cpp
+++ b/engines/dgds/scene.cpp
@@ -823,7 +823,7 @@ bool Scene::checkConditions(const Common::Array<SceneConditions> &conds) const {
 bool SDSScene::_dlgWithFlagLo8IsClosing = false;;
 DialogFlags SDSScene::_sceneDialogFlags = kDlgFlagNone;
 
-SDSScene::SDSScene() : _num(-1), _dragItem(nullptr), _shouldClearDlg(false), _ignoreMouseUp(false) {
+SDSScene::SDSScene() : _num(-1), _dragItem(nullptr), _shouldClearDlg(false), _ignoreMouseUp(false), _field6_0x14(0) {
 }
 
 bool SDSScene::load(const Common::String &filename, ResourceManager *resourceManager, Decompressor *decompressor) {
@@ -1465,6 +1465,8 @@ void SDSScene::addInvButtonToHotAreaList() {
 	area._rect.height = icons->height(2);
 	area._rect.x = SCREEN_WIDTH - area._rect.width;
 	area._rect.y = SCREEN_HEIGHT - area._rect.height;
+	area._unk1 = 0;
+	area._unk2 = 0;
 
 	_hotAreaList.push_front(area);
 }
diff --git a/engines/dgds/scene.h b/engines/dgds/scene.h
index 213234d1dfa..1e84c66bc75 100644
--- a/engines/dgds/scene.h
+++ b/engines/dgds/scene.h
@@ -184,7 +184,7 @@ private:
 
 class SceneTrigger {
 public:
-	SceneTrigger(uint16 num) : _num(num), _enabled(false) {}
+	SceneTrigger(uint16 num) : _num(num), _enabled(false), _unk(0) {}
 	Common::String dump(const Common::String &indent) const;
 
 	Common::Array<SceneConditions> conditionList;
@@ -203,7 +203,7 @@ private:
    the game */
 class PerSceneGlobal {
 public:
-	PerSceneGlobal(uint16 num, uint16 scene) : _num(num), _sceneNo(scene) {}
+	PerSceneGlobal(uint16 num, uint16 scene) : _num(num), _sceneNo(scene), _val(0) {}
 
 	Common::String dump(const Common::String &indent) const;
 	bool matches(uint16 num, uint16 scene) const { return num == _num && (_sceneNo == 0 || _sceneNo == scene); }
diff --git a/engines/dgds/ttm.cpp b/engines/dgds/ttm.cpp
index f11919d7b41..23ce7ce8786 100644
--- a/engines/dgds/ttm.cpp
+++ b/engines/dgds/ttm.cpp
@@ -43,7 +43,7 @@ void GetPutRegion::reset() {
 }
 
 Common::Error TTMEnviro::syncState(Common::Serializer &s) {
-	DgdsEngine *engine = dynamic_cast<DgdsEngine *>(g_engine);
+	DgdsEngine *engine = static_cast<DgdsEngine *>(g_engine);
 	for (auto &shape : _scriptShapes) {
 		bool hasShape = shape.get() != nullptr;
 		s.syncAsByte(hasShape);
@@ -918,7 +918,7 @@ bool TTMInterpreter::run(TTMEnviro &env, TTMSeq &seq) {
 		code = scr->readUint16LE();
 		uint16 op = code & 0xFFF0;
 		byte count = code & 0x000F;
-		int16 ivals[8];
+		int16 ivals[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 		Common::String sval;
 
 		if (count > 8 && count != 0x0f)
@@ -1024,7 +1024,7 @@ void TTMInterpreter::findAndAddSequences(TTMEnviro &env, Common::Array<TTMSeq> &
 void TTMSeq::reset() {
 	_currentFontId = 0;
 	_currentPalId = 0;
-	_currentPalId = 0;
+	_currentSongId = 0;
 	_currentBmpId = 0;
 	_currentGetPutId = 0;
 	_currentFrame = _startFrame;




More information about the Scummvm-git-logs mailing list