summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-10-02 12:00:30 +0000
committerpeter1138 <peter1138@openttd.org>2005-10-02 12:00:30 +0000
commitc294de06b93298cb1673168922983332fa46083e (patch)
treefe00666748c6d2bd7f9da98278e5547f359bd2a5
parent4fe06ceeccee9fbadf620589b143fcc0801564b4 (diff)
downloadopenttd-c294de06b93298cb1673168922983332fa46083e.tar.xz
(svn r3006) -Fix, NewGRF: Don't assert on user input, skip data instead.
-Codechange, NewGRF: Remove unnecessary NULL check.
-rw-r--r--newgrf.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/newgrf.c b/newgrf.c
index 640f4c013..ff23eded3 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -1027,13 +1027,19 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
}
for (table = tableid; table < tableid + numtables; table++) {
- assert(table < 7);
- if (bridge->sprite_table[table] == NULL) {
- bridge->sprite_table[table] = malloc(32 * sizeof(**bridge->sprite_table));
- }
+ if (table < 7) {
+ if (bridge->sprite_table[table] == NULL) {
+ bridge->sprite_table[table] = malloc(32 * sizeof(**bridge->sprite_table));
+ }
- for (sprite = 0; sprite < 32; sprite++)
- bridge->sprite_table[table][sprite] = grf_load_dword(&buf);
+ for (sprite = 0; sprite < 32; sprite++)
+ bridge->sprite_table[table][sprite] = grf_load_dword(&buf);
+ } else {
+ grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", table);
+ // Skip past invalid data.
+ for (sprite = 0; sprite < 32; sprite++)
+ grf_load_dword(&buf);
+ }
}
}
break;
@@ -2272,10 +2278,8 @@ static void ResetNewGRFData(void)
for (i = 0; i < MAX_BRIDGES; i++) {
if (_bridge[i].sprite_table != NULL) {
byte j;
- for (j = 0; j < 7; j++) {
- if (_bridge[i].sprite_table[j] != NULL)
- free(_bridge[i].sprite_table[j]);
- }
+ for (j = 0; j < 7; j++)
+ free(_bridge[i].sprite_table[j]);
free(_bridge[i].sprite_table);
}
}