[Scummvm-git-logs] scummvm master -> 07818cae583834f9ebd96304eac60f296678565b
sluicebox
noreply at scummvm.org
Mon Mar 20 20:44:33 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:
07818cae58 SCI: Add misc error handling
Commit: 07818cae583834f9ebd96304eac60f296678565b
https://github.com/scummvm/scummvm/commit/07818cae583834f9ebd96304eac60f296678565b
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2023-03-20T13:43:25-07:00
Commit Message:
SCI: Add misc error handling
Fixes several Coverity issues
Changed paths:
engines/sci/console.cpp
engines/sci/engine/savegame.cpp
engines/sci/engine/script.cpp
engines/sci/sound/drivers/pc9801.cpp
engines/sci/sound/music.cpp
engines/sci/sound/soundcmd.cpp
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 85bd113d03c..b804c1c8dbc 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -4555,6 +4555,9 @@ bool Console::cmdMapVocab994(int argc, const char **argv) {
}
Resource *resource = _engine->_resMan->findResource(ResourceId(kResourceTypeVocab, 994), false);
+ if (resource == nullptr) {
+ return true;
+ }
const Object *obj = s->_segMan->getObject(reg);
SciSpan<const uint16> data = resource->subspan<const uint16>(0);
uint32 first = atoi(argv[2]);
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index e67e4764a2d..8dd3a859093 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -1476,6 +1476,7 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
if (meta.gameObjectOffset > 0 && meta.script0Size > 0) {
Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false);
+ assert(script0);
if (script0->size() != meta.script0Size || g_sci->getGameObject().getOffset() != meta.gameObjectOffset) {
showScummVMDialog(_("This saved game was created with a different version of the game, unable to load it"));
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index cbc91293530..01e3bcf42f3 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -89,6 +89,7 @@ void Script::load(int script_nr, ResourceManager *resMan, ScriptPatcher *scriptP
_nr = script_nr;
uint32 scriptSize = script->size();
uint32 bufSize = scriptSize;
+ Resource *heap = nullptr;
if (getSciVersion() == SCI_VERSION_0_EARLY) {
bufSize += script->getUint16LEAt(0) * 2;
@@ -99,7 +100,10 @@ void Script::load(int script_nr, ResourceManager *resMan, ScriptPatcher *scriptP
// combined size of the stack and the heap must be 64KB. So far this has
// worked for SCI11, SCI2 and SCI21 games. SCI3 games use a different
// script format, and they can exceed the 64KB boundary using relocation.
- Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, script_nr), false);
+ heap = resMan->findResource(ResourceId(kResourceTypeHeap, script_nr), false);
+ if (heap == nullptr) {
+ error("Heap %d not found", script_nr);
+ }
bufSize += heap->size();
// Ensure that the start of the heap resource can be word-aligned.
@@ -136,10 +140,7 @@ void Script::load(int script_nr, ResourceManager *resMan, ScriptPatcher *scriptP
// size
_script = _buf->subspan(0, scriptSize, script->name());
- if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1_LATE) {
- Resource *heap = resMan->findResource(ResourceId(kResourceTypeHeap, _nr), false);
- assert(heap);
-
+ if (heap != nullptr) {
SciSpan<byte> outHeap = outBuffer.subspan(scriptSize, heap->size(), heap->name(), 0);
heap->copyDataTo(outHeap);
_heap = outHeap;
diff --git a/engines/sci/sound/drivers/pc9801.cpp b/engines/sci/sound/drivers/pc9801.cpp
index 1fc18a923d2..7c05c001169 100644
--- a/engines/sci/sound/drivers/pc9801.cpp
+++ b/engines/sci/sound/drivers/pc9801.cpp
@@ -1348,7 +1348,10 @@ int MidiDriver_PC9801::open() {
}
ResourceManager *resMan = g_sci->getResMan();
- if (!loadInstruments(*resMan->findResource(ResourceId(kResourceTypePatch, _version < SCI_VERSION_1_LATE ? 2 : 8), false)))
+ Resource *resource = resMan->findResource(ResourceId(kResourceTypePatch, _version < SCI_VERSION_1_LATE ? 2 : 8), false);
+ if (resource == nullptr)
+ return MERR_CANNOT_CONNECT;
+ if (!loadInstruments(*resource))
return MERR_CANNOT_CONNECT;
if (_version == SCI_VERSION_0_LATE && _channelMask2 == 0x00) {
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp
index 1b703d1ef9f..95526cce9e8 100644
--- a/engines/sci/sound/music.cpp
+++ b/engines/sci/sound/music.cpp
@@ -958,7 +958,9 @@ void SciMusic::printSongInfo(reg_t obj, Console *con) {
con->debugPrintf("Type: MIDI\n");
if (song->soundRes) {
SoundResource::Track *track = song->soundRes->getTrackByType(_pMidiDrv->getPlayId());
- con->debugPrintf("Channels: %d\n", track->channelCount);
+ if (track) {
+ con->debugPrintf("Channels: %d\n", track->channelCount);
+ }
}
} else if (song->pStreamAud || song->pLoopStream) {
con->debugPrintf("Type: digital audio (%s), sound active: %s\n",
diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp
index 591312a9d34..8009f2d7e66 100644
--- a/engines/sci/sound/soundcmd.cpp
+++ b/engines/sci/sound/soundcmd.cpp
@@ -190,7 +190,7 @@ reg_t SoundCommandParser::kDoSoundPlay(EngineState *s, int argc, reg_t *argv) {
void SoundCommandParser::processPlaySound(reg_t obj, bool playBed, bool restoring) {
MusicEntry *musicSlot = _music->getSlot(obj);
- if (!restoring && isUninterruptableSoundPlaying(obj)) {
+ if (!restoring && musicSlot && isUninterruptableSoundPlaying(obj)) {
debugC(kDebugLevelSound, "kDoSound(play): sound %d already playing", musicSlot->resourceId);
return;
}
More information about the Scummvm-git-logs
mailing list