aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kiewitz2010-05-26 20:48:08 +0000
committerMartin Kiewitz2010-05-26 20:48:08 +0000
commitd35121fc6144eb9fc9e06d60d5c8cf49f5c1b181 (patch)
treefc3faba912d5ce9fce9636156fd74dc0ab14eaf8
parent947edd08c3b60ec873fcc6c922ef4ebb34ba2305 (diff)
downloadscummvm-rg350-d35121fc6144eb9fc9e06d60d5c8cf49f5c1b181.tar.gz
scummvm-rg350-d35121fc6144eb9fc9e06d60d5c8cf49f5c1b181.tar.bz2
scummvm-rg350-d35121fc6144eb9fc9e06d60d5c8cf49f5c1b181.zip
SCI: fixing kReadNumber to behave like in sierra sci (non standard atoi implementation) - fixes big door not unlocking in sq4
svn-id: r49250
-rw-r--r--engines/sci/engine/kstring.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/engines/sci/engine/kstring.cpp b/engines/sci/engine/kstring.cpp
index 426c682e11..d7fa23116b 100644
--- a/engines/sci/engine/kstring.cpp
+++ b/engines/sci/engine/kstring.cpp
@@ -138,10 +138,28 @@ 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) {
+ result *= 10;
+ if ((*source < '0') || (*source > '9'))
+ error("Invalid character in kReadNumber input");
+ result += *source - 0x30;
+ source++;
+ }
+ }
+
+ return make_reg(0, result);
}