SCUMM: some Coverity fixes

This commit is contained in:
athrxx 2024-05-06 18:05:04 +02:00
parent b53dbf18c2
commit 158614fce6
8 changed files with 31 additions and 25 deletions

View File

@ -644,12 +644,13 @@ protected:
VideoParameters _videoParams;
int32 _heObject, _heObjectNum;
int32 _hePaletteNum;
int32 _heObject = 0;
int32 _heObjectNum = 0;
int32 _hePaletteNum = 0;
int32 _maxSpriteNum = 0;
int32 _minSpriteNum = 0;
int32 _curSpriteGroupId;
int32 _curSpriteGroupId = 0;
LogicHE *_logicHE = nullptr;
MoviePlayer *_moviePlay;
@ -783,9 +784,9 @@ protected:
byte VAR_U32_ARRAY_UNK;
#ifdef USE_ENET
byte VAR_REMOTE_START_SCRIPT;
byte VAR_NETWORK_AVAILABLE;
byte VAR_NETWORK_RECEIVE_ARRAY_SCRIPT;
byte VAR_REMOTE_START_SCRIPT = 98;
byte VAR_NETWORK_AVAILABLE = 109;
byte VAR_NETWORK_RECEIVE_ARRAY_SCRIPT = 101;
public:
int networkSessionDialog();

View File

@ -219,6 +219,7 @@ WarpWizOneSpanTable *Wiz::warpCreateSpanTable(int spanCount) {
if (!spanTable) {
return nullptr;
}
memset(spanTable, 0, sizeof(WarpWizOneSpanTable));
spanTable->spanCount = spanCount;
spanTable->spans = (WarpWizOneSpan *)malloc(spanCount * sizeof(WarpWizOneSpan));
@ -226,6 +227,7 @@ WarpWizOneSpanTable *Wiz::warpCreateSpanTable(int spanCount) {
warpDestroySpanTable(spanTable);
return nullptr;
}
memset(spanTable->spans, 0, spanCount * sizeof(WarpWizOneSpan));
spanPtr = spanTable->spans;
for (counter = 0; counter < spanCount; counter++) {
@ -239,6 +241,7 @@ WarpWizOneSpanTable *Wiz::warpCreateSpanTable(int spanCount) {
warpDestroySpanTable(spanTable);
return nullptr;
}
memset(spanTable->drawSpans, 0, spanCount * sizeof(WarpWizOneDrawSpan));
return spanTable;
}

View File

@ -45,8 +45,8 @@ namespace Scumm {
IMuseInternal::IMuseInternal(ScummEngine *vm, MidiDriverFlags sndType, bool nativeMT32) :
_native_mt32(nativeMT32),
_newSystem(vm->_game.id == GID_SAMNMAX),
_dynamicChanAllocation(vm->_game.id != GID_MONKEY2 && vm->_game.id != GID_INDY4), // For the non-iMuse games that (unfortunately) run on this player we need to pretend we're on the more modern version
_newSystem(vm && vm->_game.id == GID_SAMNMAX),
_dynamicChanAllocation(vm && (vm->_game.id != GID_MONKEY2 && vm->_game.id != GID_INDY4)), // For the non-iMuse games that (unfortunately) run on this player we need to pretend we're on the more modern version
_midi_adlib(nullptr),
_midi_native(nullptr),
_sysex(nullptr),

View File

@ -210,7 +210,7 @@ bool ScummEngine::canSaveGameStateCurrently(Common::U32String *msg) {
}
// Also deny persistence operations while the script opening the save menu is running...
isOriginalMenuActive = _currentRoom == saveRoom || vm.slot[_currentScript].number == saveMenuScript;
isOriginalMenuActive = _currentRoom == saveRoom || (_currentScript != 0xFF && vm.slot[_currentScript].number == saveMenuScript);
}
// SCUMM v4+ doesn't allow saving in room 0 or if

View File

@ -813,6 +813,7 @@ int ScummEngine::pop() {
void ScummEngine::stopObjectCode() {
ScriptSlot *ss;
assert(_currentScript != 0xFF);
ss = &vm.slot[_currentScript];
if (_game.version <= 2) {
if (ss->where == WIO_GLOBAL || ss->where == WIO_LOCAL) {

View File

@ -3321,20 +3321,20 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
const int len = resStrLen(_scriptPointer);
if (_game.id == GID_LOOM && _game.version == 4 && _language == Common::EN_ANY &&
vm.slot[_currentScript].number == 95 && enhancementEnabled(kEnhTextLocFixes) &&
_currentScript != 0xFF && vm.slot[_currentScript].number == 95 && enhancementEnabled(kEnhTextLocFixes) &&
strcmp((const char *)_scriptPointer, "I am Choas.") == 0) {
// WORKAROUND: This happens when Chaos introduces
// herself to bishop Mandible. Of all the places to put
// a typo...
printString(textSlot, (const byte *)"I am Chaos.");
} else if (_game.id == GID_LOOM && _game.version == 4 && _roomResource == 90 &&
vm.slot[_currentScript].number == 203 && _string[textSlot].color == 0x0F && enhancementEnabled(kEnhSubFmtCntChanges)) {
_currentScript != 0xFF && vm.slot[_currentScript].number == 203 && _string[textSlot].color == 0x0F && enhancementEnabled(kEnhSubFmtCntChanges)) {
// WORKAROUND: When Mandible speaks with Goodmold, his second
// speech line is missing its color parameter.
_string[textSlot].color = 0x0A;
printString(textSlot, _scriptPointer);
} else if (_game.id == GID_INDY3 && _game.platform == Common::kPlatformFMTowns && _roomResource == 80 &&
vm.slot[_currentScript].number == 201 && enhancementEnabled(kEnhSubFmtCntChanges)) {
_currentScript != 0xFF && vm.slot[_currentScript].number == 201 && enhancementEnabled(kEnhSubFmtCntChanges)) {
// WORKAROUND: When Indy and his father escape the zeppelin
// with the biplane in the FM-TOWNS version, they share the
// same text color. Indeed, they're not given any explicit
@ -3347,8 +3347,8 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
else
_string[textSlot].color = 0x0E;
printString(textSlot, _scriptPointer);
} else if (_game.id == GID_INDY4 && _roomResource == 23 && vm.slot[_currentScript].number == 167 &&
len == 24 && enhancementEnabled(kEnhTextLocFixes) && memcmp(_scriptPointer+16, "pregod", 6) == 0) {
} else if (_game.id == GID_INDY4 && _roomResource == 23 && _currentScript != 0xFF && vm.slot[_currentScript].number == 167 &&
len == 24 && enhancementEnabled(kEnhTextLocFixes) && memcmp(_scriptPointer+16, "pregod", 6) == 0) {
// WORKAROUND for bug #2961: At the end of Indy4, if Ubermann is told
// to use 20 orichalcum beads, he'll count "pregod8" and "pregod9"
// instead of "18" and "19", in some releases.
@ -3364,7 +3364,7 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
Common::strlcpy((char *)tmpBuf+16, "^19^", sizeof(tmpBuf) - 16);
printString(textSlot, tmpBuf);
} else if (_game.id == GID_INDY4 && _language == Common::EN_ANY && _roomResource == 10 &&
vm.slot[_currentScript].number == 209 && _actorToPrintStrFor == 4 && len == 81 &&
_currentScript != 0xFF && vm.slot[_currentScript].number == 209 && _actorToPrintStrFor == 4 && len == 81 &&
strcmp(_game.variant, "Floppy") != 0 && enhancementEnabled(kEnhSubFmtCntChanges)) {
// WORKAROUND: The English Talkie version of Indy4 changed Kerner's
// lines when he uses the phone booth in New York, but the text doesn't
@ -3381,8 +3381,8 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
} else {
printString(textSlot, _scriptPointer);
}
} else if (_game.id == GID_INDY4 && vm.slot[_currentScript].number == 161 && _actorToPrintStrFor == 2 &&
_game.platform != Common::kPlatformAmiga && strcmp(_game.variant, "Floppy") != 0 &&
} else if (_game.id == GID_INDY4 && _currentScript != 0xFF && vm.slot[_currentScript].number == 161 && _actorToPrintStrFor == 2 &&
_game.platform != Common::kPlatformAmiga && strcmp(_game.variant, "Floppy") != 0 &&
enhancementEnabled(kEnhAudioChanges)) {
// WORKAROUND: In Indy 4, if one plays as Sophia and looks at Indy, then
// her "There's nothing to look at." reaction line will be said with
@ -3390,7 +3390,7 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
// case. Script 68-4 has a "There's nothing to look at." line for Sophia,
// though, so we reuse this if the current line contains the expected
// audio offset.
if (memcmp(_scriptPointer, "\xFF\x0A\x5D\x8E\xFF\x0A\x63\x08\xFF\x0A\x0E\x00\xFF\x0A\x00\x00", 16) == 0) {
if (memcmp(_scriptPointer, "\xFF\x0A\x5D\x8E\xFF\x0A\x63\x08\xFF\x0A\x0E\x00\xFF\x0A\x00\x00", 16) == 0 && len >= 16) {
byte *tmpBuf = new byte[len];
memcpy(tmpBuf, "\xFF\x0A\xCE\x3B\xFF\x0A\x01\x05\xFF\x0A\x0E\x00\xFF\x0A\x00\x00", 16);
memcpy(tmpBuf + 16, _scriptPointer + 16, len - 16);
@ -3399,8 +3399,8 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
} else {
printString(textSlot, _scriptPointer);
}
} else if (_game.id == GID_MONKEY_EGA && _roomResource == 30 && vm.slot[_currentScript].number == 411 &&
strstr((const char *)_scriptPointer, "NCREDIT-NOTE-AMOUNT")) {
} else if (_game.id == GID_MONKEY_EGA && _roomResource == 30 && _currentScript != 0xFF && vm.slot[_currentScript].number == 411 &&
strstr((const char *)_scriptPointer, "NCREDIT-NOTE-AMOUNT")) {
// WORKAROUND for bug #4886 (MI1EGA German: Credit text incorrect)
// The script contains buggy text.
const char *tmp = strstr((const char *)_scriptPointer, "NCREDIT-NOTE-AMOUNT");
@ -3411,8 +3411,8 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
Common::strlcpy(tmpBuf + diff + 4, tmp + sizeof("NCREDIT-NOTE-AMOUNT") - 1, sizeof(tmpBuf) - diff - 4);
printString(textSlot, (byte *)tmpBuf);
} else if (_game.id == GID_MONKEY && !(_game.features & GF_ULTIMATE_TALKIE) &&
_game.platform != Common::kPlatformSegaCD &&
((_roomResource == 78 && vm.slot[_currentScript].number == 201) ||
_game.platform != Common::kPlatformSegaCD &&
_currentScript != 0xFF && ((_roomResource == 78 && vm.slot[_currentScript].number == 201) ||
(_roomResource == 45 && vm.slot[_currentScript].number == 200 &&
isValidActor(10) && _actors[10]->isInCurrentRoom())) &&
_actorToPrintStrFor == 255 && _string[textSlot].color != 0x0F &&
@ -3425,7 +3425,7 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
_string[textSlot].color = (_game.platform == Common::kPlatformFMTowns) ? 0x0A : 0xF9;
printString(textSlot, _scriptPointer);
} else if (_game.id == GID_MONKEY && !(_game.features & GF_ULTIMATE_TALKIE) &&
_game.platform != Common::kPlatformSegaCD &&
_game.platform != Common::kPlatformSegaCD && _currentScript != 0xFF &&
(vm.slot[_currentScript].number == 140 || vm.slot[_currentScript].number == 294) &&
_actorToPrintStrFor == 255 && _string[textSlot].color == 0x06 &&
enhancementEnabled(kEnhSubFmtCntChanges)) {
@ -3438,7 +3438,7 @@ void ScummEngine_v5::decodeParseStringTextString(int textSlot) {
// different releases and scenes, so we don't know the original intent.
_string[textSlot].color = (_game.platform == Common::kPlatformFMTowns) ? 0x0C : 0xEA;
printString(textSlot, _scriptPointer);
} else if (_game.id == GID_MONKEY && _roomResource == 25 && vm.slot[_currentScript].number == 205) {
} else if (_game.id == GID_MONKEY && _roomResource == 25 && _currentScript != 0xFF && vm.slot[_currentScript].number == 205) {
printPatchedMI1CannibalString(textSlot, _scriptPointer);
} else {
printString(textSlot, _scriptPointer);

View File

@ -2001,7 +2001,7 @@ void ScummEngine_v6::o6_roomOps() {
// this way, we avoid some graphics glitches that the original
// interpreter had.
if (_game.id == GID_SAMNMAX && vm.slot[_currentScript].number == 64)
if (_game.id == GID_SAMNMAX && _currentScript != 0xFF && vm.slot[_currentScript].number == 64)
setDirtyColors(0, 255);
else
setCurrentPalette(a);

View File

@ -3188,6 +3188,7 @@ void ScummEngine_v3::terminateSaveMenuScript() {
int cur = _currentScript;
int scriptToChain = _game.platform == Common::kPlatformFMTowns ? 6 : 5;
assert(cur != 0xFF);
chainedArgs[0] = 0;
vm.slot[cur].number = 0;
vm.slot[cur].status = ssDead;