diff options
-rw-r--r-- | engines/sci/engine/kernel32.cpp | 12 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.h | 15 |
3 files changed, 21 insertions, 10 deletions
diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp index 5975c7b3bc..25a822f77d 100644 --- a/engines/sci/engine/kernel32.cpp +++ b/engines/sci/engine/kernel32.cpp @@ -609,13 +609,15 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { if (argv[1].segment == s->_segMan->getSysStringsSegment()) { // Resize if necessary const uint16 sysStringId = argv[1].toUint16(); - if ((uint32)s->_segMan->_sysStrings->_strings[sysStringId]._maxSize < index1 + count) { - free(s->_segMan->_sysStrings->_strings[sysStringId]._value); - s->_segMan->_sysStrings->_strings[sysStringId]._maxSize = index1 + count; - s->_segMan->_sysStrings->_strings[sysStringId]._value = (char *)calloc(index1 + count, sizeof(char)); + SystemString *sysString = s->_segMan->getSystemString(sysStringId); + assert(sysString); + if ((uint32)sysString->_maxSize < index1 + count) { + free(sysString->_value); + sysString->_maxSize = index1 + count; + sysString->_value = (char *)calloc(index1 + count, sizeof(char)); } - strncpy(s->_segMan->_sysStrings->_strings[sysStringId]._value + index1, string2 + index2, count); + strncpy(sysString->_value + index1, string2 + index2, count); } else { SciString *string1 = s->_segMan->lookupString(argv[1]); diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 517e723d40..a5cfc5013b 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -85,7 +85,7 @@ void SegManager::initSysStrings() { _sysStrings = (SystemStrings *)allocSegment(new SystemStrings(), &_sysStringsSegId); // Allocate static buffer for savegame and CWD directories - SystemString *strSaveDir = &_sysStrings->_strings[SYS_STRING_SAVEDIR]; + SystemString *strSaveDir = getSystemString(SYS_STRING_SAVEDIR); strSaveDir->_name = "savedir"; strSaveDir->_maxSize = MAX_SAVE_DIR_SIZE; strSaveDir->_value = (char *)calloc(MAX_SAVE_DIR_SIZE, sizeof(char)); @@ -94,7 +94,7 @@ void SegManager::initSysStrings() { ::strcpy(strSaveDir->_value, ""); // Allocate static buffer for the parser base - SystemString *strParserBase = &_sysStrings->_strings[SYS_STRING_PARSER_BASE]; + SystemString *strParserBase = getSystemString(SYS_STRING_PARSER_BASE); strParserBase->_name = "parser-base"; strParserBase->_maxSize = MAX_PARSER_BASE; strParserBase->_value = (char *)calloc(MAX_PARSER_BASE, sizeof(char)); diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 50a0464ee2..6fb1114555 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -448,6 +448,18 @@ public: */ SegmentId getSysStringsSegment() { return _sysStringsSegId; } + /** + * Get a pointer to the system string with the specified index, + * or NULL if that index is invalid. + * + * This method is currently only used by kString(). + */ + SystemString *getSystemString(uint idx) const { + if (idx >= SYS_STRINGS_MAX) + return NULL; + return &_sysStrings->_strings[idx]; + } + public: // TODO: make private Common::Array<SegmentObj *> _heap; // Only accessible from saveLoadWithSerializer() @@ -476,11 +488,8 @@ private: /* System strings */ SegmentId _sysStringsSegId; -public: // TODO: make private. Only kString() needs direct access SystemStrings *_sysStrings; -private: - #ifdef ENABLE_SCI32 SegmentId _arraysSegId; SegmentId _stringSegId; |