[Scummvm-git-logs] scummvm master -> 9b81a24ada6f4e1751d759028c7d286f36c62bcd

AndywinXp noreply at scummvm.org
Mon Aug 21 12:26:04 UTC 2023


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:
9b81a24ada SCUMM: HE (Sound): Fix Coverity issues


Commit: 9b81a24ada6f4e1751d759028c7d286f36c62bcd
    https://github.com/scummvm/scummvm/commit/9b81a24ada6f4e1751d759028c7d286f36c62bcd
Author: AndywinXp (andywinxp at gmail.com)
Date: 2023-08-21T14:25:52+02:00

Commit Message:
SCUMM: HE (Sound): Fix Coverity issues

Issues fixed:
CID 1230332
CID 1518552
CID 1518553
CID 1518554
CID 1518555
CID 1518556
CID 1518560
CID 1518561
CID 1518562

Changed paths:
    engines/scumm/he/intern_he.h
    engines/scumm/he/mixer_he.cpp
    engines/scumm/he/sound_he.cpp
    engines/scumm/he/sound_he.h


diff --git a/engines/scumm/he/intern_he.h b/engines/scumm/he/intern_he.h
index b4f57e09350..804793338be 100644
--- a/engines/scumm/he/intern_he.h
+++ b/engines/scumm/he/intern_he.h
@@ -380,7 +380,7 @@ protected:
 
 #include "common/pack-end.h"	// END STRUCT PACKING
 
-	int _stringLength;
+	int _stringLength = 1;
 	byte _stringBuffer[4096];
 
 	WizParameters _wizParams;
@@ -497,7 +497,8 @@ protected:
 
 class ScummEngine_v80he : public ScummEngine_v72he {
 protected:
-	int32 _heSndResId;
+	int32 _heSndResId = 0;
+
 	enum SubOpType {
 		SO_CURSOR_IMAGE = 19,
 		SO_CURSOR_COLOR_IMAGE = 20,
diff --git a/engines/scumm/he/mixer_he.cpp b/engines/scumm/he/mixer_he.cpp
index 0fc9258f524..74f6d6be054 100644
--- a/engines/scumm/he/mixer_he.cpp
+++ b/engines/scumm/he/mixer_he.cpp
@@ -440,7 +440,7 @@ bool HEMixer::mixerIsMixerDisabled() {
 }
 
 bool HEMixer::mixerStopChannel(int channel) {
-	if ((0 <= channel) && (MIXER_MAX_CHANNELS > channel))
+	if ((channel >= 0) && (channel < MIXER_MAX_CHANNELS))
 		return mixerStartChannel(channel, 0, 0, 0, 0, 0, 0, 0, CHANNEL_EMPTY_FLAGS);
 
 	return false;
@@ -468,7 +468,7 @@ bool HEMixer::mixerStartChannel(
 
 	va_list params;
 
-	if ((channel < 0) || (channel > MIXER_MAX_CHANNELS))
+	if ((channel < 0) || (channel >= MIXER_MAX_CHANNELS))
 		return false;
 
 	if (_mixerChannels[channel].flags != CHANNEL_EMPTY_FLAGS) {
@@ -651,7 +651,7 @@ bool HEMixer::mixerStartSpoolingChannel(
 
 	uint32 initialReadCount;
 
-	if ((channel < 0) || (channel > MIXER_MAX_CHANNELS))
+	if ((channel < 0) || (channel >= MIXER_MAX_CHANNELS))
 		return false;
 
 	if (_mixerChannels[channel].flags != CHANNEL_EMPTY_FLAGS) {
@@ -1302,11 +1302,14 @@ void HEMilesChannel::serviceStream() {
 			sizeToRead = MIN<uint32>(MILES_PCM_CHUNK_SIZE * _blockAlign, _stream.dataLength - _stream.curDataPos);
 			reachedTheEnd = sizeToRead < MILES_PCM_CHUNK_SIZE * _blockAlign;
 
-			byte *buffer = (byte *)malloc(sizeToRead);
-			if (sizeToRead > 0 && buffer != nullptr) {
-				int readBytes = _stream.fileHandle->read(buffer, sizeToRead);
-				_stream.curDataPos += readBytes;
-				_stream.streamObj->queueBuffer(buffer, readBytes, DisposeAfterUse::YES, getOutputFlags());
+
+			if (sizeToRead > 0) {
+				byte *buffer = (byte *)malloc(sizeToRead);
+				if (buffer != nullptr) {
+					int readBytes = _stream.fileHandle->read(buffer, sizeToRead);
+					_stream.curDataPos += readBytes;
+					_stream.streamObj->queueBuffer(buffer, readBytes, DisposeAfterUse::YES, getOutputFlags());
+				}
 			}
 
 		} else if (_dataFormat == WAVE_FORMAT_IMA_ADPCM) {
@@ -1320,30 +1323,32 @@ void HEMilesChannel::serviceStream() {
 
 			// We allocate a buffer which is going to be filled with
 			// (MILES_IMA_ADPCM_PER_FRAME_CHUNKS_NUM) compressed blocks or less
-			byte *compressedBuffer = (byte *)malloc(sizeToRead);
-			if (sizeToRead > 0 && compressedBuffer != nullptr) {
-				int readBytes = _stream.fileHandle->read(compressedBuffer, sizeToRead);
-				_stream.curDataPos += readBytes;
-
-				// Now, the ugly trick: use a MemoryReadStream containing our compressed data,
-				// to feed an ADPCM stream, and then use the latter to read uncompressed data,
-				// and then queue the latter in the output stream.
-				// Hey, it IS ugly! ...and it works :-)
-				Common::MemoryReadStream memStream(compressedBuffer, readBytes);
-				Audio::AudioStream *adpcmStream = Audio::makeADPCMStream(&memStream, DisposeAfterUse::NO,
-					readBytes, Audio::kADPCMMSIma, _baseFrequency, _numChannels, _blockAlign);
-
-				uint32 uncompSize =
-					calculateDeflatedADPCMBlockSize(MILES_IMA_ADPCM_PER_FRAME_CHUNKS_NUM, _blockAlign, _numChannels, 16);
-
-				byte *adpcmData = (byte *)malloc(uncompSize);
-				uint32 adpcmSize = adpcmStream->readBuffer((int16 *)(void *)adpcmData, uncompSize * 2);
-
-				adpcmSize *= 2;
-				_stream.streamObj->queueBuffer(adpcmData, adpcmSize, DisposeAfterUse::YES, getOutputFlags());
-
-				delete adpcmStream;
-				free(compressedBuffer);
+			if (sizeToRead > 0) {
+				byte *compressedBuffer = (byte *)malloc(sizeToRead);
+				if (compressedBuffer != nullptr){
+					int readBytes = _stream.fileHandle->read(compressedBuffer, sizeToRead);
+					_stream.curDataPos += readBytes;
+
+					// Now, the ugly trick: use a MemoryReadStream containing our compressed data,
+					// to feed an ADPCM stream, and then use the latter to read uncompressed data,
+					// and then queue the latter in the output stream.
+					// Hey, it IS ugly! ...and it works :-)
+					Common::MemoryReadStream memStream(compressedBuffer, readBytes);
+					Audio::AudioStream *adpcmStream = Audio::makeADPCMStream(&memStream, DisposeAfterUse::NO,
+																			 readBytes, Audio::kADPCMMSIma, _baseFrequency, _numChannels, _blockAlign);
+
+					uint32 uncompSize =
+						calculateDeflatedADPCMBlockSize(MILES_IMA_ADPCM_PER_FRAME_CHUNKS_NUM, _blockAlign, _numChannels, 16);
+
+					byte *adpcmData = (byte *)malloc(uncompSize);
+					uint32 adpcmSize = adpcmStream->readBuffer((int16 *)(void *)adpcmData, uncompSize * 2);
+
+					adpcmSize *= 2;
+					_stream.streamObj->queueBuffer(adpcmData, adpcmSize, DisposeAfterUse::YES, getOutputFlags());
+
+					delete adpcmStream;
+					free(compressedBuffer);
+				}
 			}
 		}
 
diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp
index fd2d976925c..deeba7aea04 100644
--- a/engines/scumm/he/sound_he.cpp
+++ b/engines/scumm/he/sound_he.cpp
@@ -61,6 +61,7 @@ SoundHE::SoundHE(ScummEngine *parent, Audio::Mixer *mixer, Common::Mutex *mutex)
 	_baseSndSize = 0;
 
 	memset(_heChannel, 0, sizeof(_heChannel));
+	memset(_soundCallbackScripts, 0, sizeof(_soundCallbackScripts));
 
 	bool useMilesSoundSystem =
 		parent->_game.id == GID_MOONBASE ||
@@ -78,6 +79,8 @@ SoundHE::~SoundHE() {
 
 	if (_heSpoolingMusicFile.isOpen())
 		_heSpoolingMusicFile.close();
+
+	delete _heMixer;
 }
 
 void SoundHE::startSound(int sound, int heOffset, int heChannel, int heFlags, int heFreq, int hePan, int heVol) {
@@ -403,13 +406,7 @@ int SoundHE::getSoundVar(int sound, int var) {
 
 	assertRange(0, var, HSND_MAX_SOUND_VARS - 1, "sound variable");
 
-	int chan = -1;
-	for (int i = 0; i < ARRAYSIZE(_heChannel); i ++) {
-		if (_heChannel[i].sound == sound)
-			chan = i;
-	}
-
-	chan = hsFindSoundChannel(sound);
+	int chan = hsFindSoundChannel(sound);
 
 	if (chan != -1) {
 		debug(5, "SoundHE::getSoundVar(): sound %d var %d result %d", sound, var, _heChannel[chan].soundVars[var]);
diff --git a/engines/scumm/he/sound_he.h b/engines/scumm/he/sound_he.h
index 5fb2d284bf9..e494f5dd6dc 100644
--- a/engines/scumm/he/sound_he.h
+++ b/engines/scumm/he/sound_he.h
@@ -262,7 +262,7 @@ protected:
 	void processSoundQueues() override;
 
 private:
-	int _heTalkOffset;
+	int _heTalkOffset = 0;
 	bool _stopActorTalkingFlag = false;
 	bool _inSoundCallbackFlag = false;
 	int _soundCallbacksQueueSize = 0;




More information about the Scummvm-git-logs mailing list