From 1f54cdf90d5d14c4acee4cd2a358585b43abb188 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 1 Jun 2010 15:38:34 +0000 Subject: [PATCH] SCI: Fix malloc<->new mismatch in SysStrings, try to increase readability svn-id: r49375 --- engines/sci/engine/kernel32.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/engines/sci/engine/kernel32.cpp b/engines/sci/engine/kernel32.cpp index 3dd596494d4..b1325432069 100644 --- a/engines/sci/engine/kernel32.cpp +++ b/engines/sci/engine/kernel32.cpp @@ -577,14 +577,14 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) { // We have a special case here for argv[1] being a system string if (argv[1].segment == s->_segMan->getSysStringsSegment()) { // Resize if necessary - if ((uint32)s->_segMan->sysStrings->_strings[argv[1].toUint16()]._maxSize < index1 + count) { - delete[] s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value; - s->_segMan->sysStrings->_strings[argv[1].toUint16()]._maxSize = index1 + count; - s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value = new char[index1 + count]; - memset(s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value, 0, index1 + count); + 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)); } - strncpy(s->_segMan->sysStrings->_strings[argv[1].toUint16()]._value + index1, string2.c_str() + index2, count); + strncpy(s->_segMan->sysStrings->_strings[sysStringId]._value + index1, string2.c_str() + index2, count); } else { SciString *string1 = s->_segMan->lookupString(argv[1]);