diff options
author | rubidium <rubidium@openttd.org> | 2008-08-16 21:48:28 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-08-16 21:48:28 +0000 |
commit | 5314e27ff11fcd8be62ff5406b37b8738bc27bee (patch) | |
tree | efaf1b8c27f9fc37073079ff335b7cb88cada43e | |
parent | 0b2c6bc2b3ccb19f3290bae8491eb79ca1ef6627 (diff) | |
download | openttd-5314e27ff11fcd8be62ff5406b37b8738bc27bee.tar.xz |
(svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
-rw-r--r-- | src/newgrf_text.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index b87c79458..ce3bda10c 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -239,8 +239,8 @@ char *TranslateTTDPatchCodes(uint32 grfid, const char *str) case 0x80: d += Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD + c - 0x7B); break; case 0x81: { StringID string; - string = *str++; - string |= *str++ << 8; + string = ((uint8)*str++); + string |= ((uint8)*str++) << 8; d += Utf8Encode(d, SCC_STRING_ID); d += Utf8Encode(d, MapGRFStringID(grfid, string)); break; @@ -271,14 +271,22 @@ char *TranslateTTDPatchCodes(uint32 grfid, const char *str) case 0x9A: switch (*str++) { case 0: /* FALL THROUGH */ - case 1: d += Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_CURRENCY); break; + case 1: + d += Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_CURRENCY); + break; case 3: { - uint16 tmp = *str++; - tmp |= (*str++) << 8; - d += Utf8Encode(d, SCC_NEWGRF_PUSH_WORD); d += Utf8Encode(d, tmp); + uint16 tmp = ((uint8)*str++); + tmp |= ((uint8)*str++) << 8; + d += Utf8Encode(d, SCC_NEWGRF_PUSH_WORD); + d += Utf8Encode(d, tmp); } break; - case 4: d += Utf8Encode(d, SCC_NEWGRF_UNPRINT); d += Utf8Encode(d, *str++); break; - default: grfmsg(1, "missing handler for extended format code"); break; + case 4: + d += Utf8Encode(d, SCC_NEWGRF_UNPRINT); + d += Utf8Encode(d, *str++); + break; + default: + grfmsg(1, "missing handler for extended format code"); + break; } break; |