commit a8549c7bd712b88169f1d4d89132f6d6097ffc9e
Author: LePhilousophe <lephilousophe@users.sourceforge.net>
Date: Wed Jul 6 23:32:54 2011 +0200
Fix rawString pointer getting invalid when allocation of new string
using push_back moved the data elsewhere
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 9f10691..1333ca1 100644
a
|
b
|
reg_t kString(EngineState *s, int argc, reg_t *argv) {
|
731 | 731 | const char *rawString = 0; |
732 | 732 | uint32 size = 0; |
733 | 733 | |
| 734 | // We allocate the new string first because if the StringTable needs to grow our rawString pointer will be invalidated |
| 735 | reg_t stringHandle; |
| 736 | SciString *dupString = s->_segMan->allocateString(&stringHandle); |
| 737 | |
734 | 738 | if (argv[1].segment == s->_segMan->getStringSegmentId()) { |
735 | 739 | SciString *string = s->_segMan->lookupString(argv[1]); |
736 | 740 | rawString = string->getRawData(); |
… |
… |
reg_t kString(EngineState *s, int argc, reg_t *argv) {
|
741 | 745 | size = string.size() + 1; |
742 | 746 | } |
743 | 747 | |
744 | | reg_t stringHandle; |
745 | | SciString *dupString = s->_segMan->allocateString(&stringHandle); |
746 | 748 | dupString->setSize(size); |
747 | 749 | |
748 | 750 | for (uint32 i = 0; i < size; i++) |