Ticket #9376: invalid-pointer.patch

File invalid-pointer.patch, 1.2 KB (added by SF/lephilousophe, 9 years ago)

Proposed fix

  • engines/sci/engine/kstring.cpp

    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) {  
    731731                const char *rawString = 0;
    732732                uint32 size = 0;
    733733
     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
    734738                if (argv[1].segment == s->_segMan->getStringSegmentId()) {
    735739                        SciString *string = s->_segMan->lookupString(argv[1]);
    736740                        rawString = string->getRawData();
    reg_t kString(EngineState *s, int argc, reg_t *argv) {  
    741745                        size = string.size() + 1;
    742746                }
    743747
    744                 reg_t stringHandle;
    745                 SciString *dupString = s->_segMan->allocateString(&stringHandle);
    746748                dupString->setSize(size);
    747749
    748750                for (uint32 i = 0; i < size; i++)