summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-16 21:48:28 +0000
committerrubidium <rubidium@openttd.org>2008-08-16 21:48:28 +0000
commit9648bf3019f6f2cb4daace12f75f097626005578 (patch)
treeefaf1b8c27f9fc37073079ff335b7cb88cada43e
parent25a1c59abb7117df6d4b0de6c41fbc388b3c5f73 (diff)
downloadopenttd-9648bf3019f6f2cb4daace12f75f097626005578.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.cpp24
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;