Skip to content

Commit 1e363fa

Browse files
committed
MM: MM1: Guard against invalid portraits when loading savegames
1 parent 8482ac7 commit 1e363fa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

engines/mm/mm1/data/character.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,15 @@ void Character::synchronize(Common::Serializer &s, int portraitNum) {
227227
s.syncAsByte(_worthiness);
228228
s.syncAsByte(_alignmentCtr);
229229
s.syncBytes(_flags, 14);
230+
230231
s.syncAsByte(_portrait);
231-
if (s.isLoading() && portraitNum != -1)
232-
_portrait = portraitNum;
232+
if (s.isLoading()) {
233+
if (portraitNum != -1)
234+
_portrait = portraitNum;
235+
else if (portraitNum >= NUM_PORTRAITS)
236+
// Ensure only valid portrait numbers are specified
237+
_portrait = 0;
238+
}
233239

234240
if (s.isLoading())
235241
loadFaceSprites();

0 commit comments

Comments
 (0)