From 2973862488aebfbcdd954701ee1cf5875da5dda1 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 28 Dec 2009 14:22:11 +0000 Subject: Added a workaround for an off-by-one invalid species access bug in the LSL2 demo svn-id: r46673 --- engines/sci/engine/vm.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index c483da7723..504f70b7ed 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1591,11 +1591,17 @@ int script_instantiate_sci0(ResourceManager *resMan, SegManager *segMan, int scr int species; species = scr->getHeap(addr.offset - SCRIPT_OBJECT_MAGIC_OFFSET + SCRIPT_SPECIES_OFFSET); if (species < 0 || species >= (int)segMan->_classtable.size()) { - warning("Invalid species %d(0x%x) not in interval " - "[0,%d) while instantiating script %d\n", - species, species, segMan->_classtable.size(), - script_nr); - return 0; + if (species == (int)segMan->_classtable.size()) { + // Happens in the LSL2 demo + warning("Applying workaround for an off-by-one invalid species access"); + segMan->_classtable.resize(segMan->_classtable.size() + 1); + } else { + warning("Invalid species %d(0x%x) not in interval " + "[0,%d) while instantiating script %d\n", + species, species, segMan->_classtable.size(), + script_nr); + return 0; + } } segMan->_classtable[species].reg = addr; -- cgit v1.2.3