aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine/kstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine/kstring.cpp')
-rw-r--r--engines/sci/engine/kstring.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index c3c10bd2a2..b383f88840 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -238,14 +238,14 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) {
/* int writelength; -- unused atm */
- if (xfer && (isdigit(xfer) || xfer == '-' || xfer == '=')) {
+ if (xfer && (isdigit(static_cast<unsigned char>(xfer)) || xfer == '-' || xfer == '=')) {
char *destp;
if (xfer == '0')
fillchar = '0';
else if (xfer == '=')
align = ALIGN_CENTER;
- else if (isdigit(xfer) || (xfer == '-'))
+ else if (isdigit(static_cast<unsigned char>(xfer)) || (xfer == '-'))
source--; // Go to start of length argument
str_leng = strtol(source, &destp, 10);
@@ -336,8 +336,9 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) {
if (align >= 0)
while (str_leng-- > 1)
*target++ = ' '; /* Format into the text */
-
- *target++ = arguments[paramindex++];
+ char argchar = arguments[paramindex++];
+ if (argchar)
+ *target++ = argchar;
mode = 0;
}
break;
@@ -427,7 +428,7 @@ reg_t kGetFarText(EngineState *s, int argc, reg_t *argv) {
}
seeker = (char *)textres->data;
-
+
// The second parameter (counter) determines the number of the string
// inside the text resource.
while (counter--) {
@@ -715,7 +716,7 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) {
// triggers an assert when doing string2[i + index2].
for (uint16 i = 0; i < count; i++)
string1->setValue(i + index1, string2[i + index2]);
-
+
return strAddress;
}
case 7: { // Cmp
@@ -730,6 +731,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 +746,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++)
@@ -781,14 +784,14 @@ reg_t kString(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
case 15: { // upper
Common::String string = s->_segMan->getString(argv[1]);
-
+
string.toUppercase();
s->_segMan->strcpy(argv[1], string.c_str());
return NULL_REG;
}
case 16: { // lower
Common::String string = s->_segMan->getString(argv[1]);
-
+
string.toLowercase();
s->_segMan->strcpy(argv[1], string.c_str());
return NULL_REG;