diff options
Diffstat (limited to 'engines/sci/engine/kstring.cpp')
-rw-r--r-- | engines/sci/engine/kstring.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp index 426c682e11..2681b612e9 100644 --- a/engines/sci/engine/kstring.cpp +++ b/engines/sci/engine/kstring.cpp @@ -138,10 +138,36 @@ reg_t kReadNumber(EngineState *s, int argc, reg_t *argv) { while (isspace((unsigned char)*source)) source++; /* Skip whitespace */ - if (*source == '$') /* SCI uses this for hex numbers */ - return make_reg(0, (int16)strtol(source + 1, NULL, 16)); /* Hex */ - else - return make_reg(0, (int16)strtol(source, NULL, 10)); /* Force decimal */ + int16 result = 0; + + if (*source == '$') { + // hexadecimal input + result = (int16)strtol(source + 1, NULL, 16); + } else { + // decimal input, we can not use strtol/atoi in here, because sierra used atoi BUT it was a non standard compliant + // atoi, that didnt do clipping. In SQ4 we get the door code in here and that's even larger than uint32! + if (*source == '-') { + result = -1; + source++; + } + while (*source) { + if ((*source < '0') || (*source > '9')) { + // Sierras atoi stopped processing at anything different than number + // Sometimes the input has a trailing space, that's fine (example: lsl3) + if (*source != ' ') { + // TODO: this happens in lsl5 right in the intro -> we get '1' '3' 0xCD 0xCD 0xCD 0xCD 0xCD + // find out why this happens and fix it + warning("Invalid character in kReadNumber input"); + } + break; + } + result *= 10; + result += *source - 0x30; + source++; + } + } + + return make_reg(0, result); } @@ -241,7 +267,7 @@ reg_t kFormat(EngineState *s, int argc, reg_t *argv) { #ifdef ENABLE_SCI32 // If the string is a string object, get to the actual string in the data selector if (s->_segMan->isObject(reg)) - reg = GET_SEL32(s->_segMan, reg, SELECTOR(data)); + reg = readSelector(s->_segMan, reg, SELECTOR(data)); #endif Common::String tempsource = (reg == NULL_REG) ? "" : g_sci->getKernel()->lookupText(reg, |