From 72da8ef5adf82d8a65da299207f30af5058ca8a9 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 7 Jul 2011 03:42:08 +0300 Subject: SCI: Applied patch #3357096 with minor modifications This prevents a string pointer from getting invalidated under some circumstances in kString(Dup). Thanks to lephilousophe for the patch. --- engines/sci/engine/kstring.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 9f10691767..7b8db22e3f 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -730,6 +730,10 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { case 8: { // Dup const char *rawString = 0; uint32 size = 0; + reg_t stringHandle; + // We allocate the new string first because if the StringTable needs to + // grow, our rawString pointer will be invalidated + SciString *dupString = s->_segMan->allocateString(&stringHandle); if (argv[1].segment == s->_segMan->getStringSegmentId()) { SciString *string = s->_segMan->lookupString(argv[1]); @@ -741,8 +745,6 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { size = string.size() + 1; } - reg_t stringHandle; - SciString *dupString = s->_segMan->allocateString(&stringHandle); dupString->setSize(size); for (uint32 i = 0; i < size; i++) -- cgit v1.2.3