aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine/klists.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2010-11-17 21:47:05 +0000
committerFilippos Karapetis2010-11-17 21:47:05 +0000
commitbd844a8c92e4176f613d358425cc3eeb0ead2bda (patch)
treeec83da247817ba18f0185e763bbe0ceaab1ee05c /engines/sci/engine/klists.cpp
parentddbda3eb152d94127369975cf4b436c3dfd072df (diff)
downloadscummvm-rg350-bd844a8c92e4176f613d358425cc3eeb0ead2bda.tar.gz
scummvm-rg350-bd844a8c92e4176f613d358425cc3eeb0ead2bda.tar.bz2
scummvm-rg350-bd844a8c92e4176f613d358425cc3eeb0ead2bda.zip
SCI: Call lookupArray() after allocateArray() when duplicating arrays
This ensures that the pointer to the element that lookupArray() returned won't be invalidated in case the array is reallocated because of allocateArray() - same issue as in kClone() svn-id: r54306
Diffstat (limited to 'engines/sci/engine/klists.cpp')
-rw-r--r--engines/sci/engine/klists.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/engines/sci/engine/klists.cpp b/engines/sci/engine/klists.cpp
index 2188087b8c..ca23469e44 100644
--- a/engines/sci/engine/klists.cpp
+++ b/engines/sci/engine/klists.cpp
@@ -702,9 +702,12 @@ reg_t kArray(EngineState *s, int argc, reg_t *argv) {
// Not implemented in SSCI
return s->r_acc;
case 8: { // Dup
- SciArray<reg_t> *array = s->_segMan->lookupArray(argv[1]);
reg_t arrayHandle;
SciArray<reg_t> *dupArray = s->_segMan->allocateArray(&arrayHandle);
+ // This must occur after allocateArray, as inserting a new object
+ // in the heap object list might invalidate this pointer. Also refer
+ // to the same issue in kClone()
+ SciArray<reg_t> *array = s->_segMan->lookupArray(argv[1]);
dupArray->setType(array->getType());
dupArray->setSize(array->getSize());