summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-04-15 16:03:45 +0000
committerDarkvater <darkvater@openttd.org>2006-04-15 16:03:45 +0000
commit5c9acdb1825b699f9d796b06df728429e0b8a87e (patch)
tree801d1ab1cc66a812ab9fb1f9e278d0bfe2f5bde9
parent88e0bab283e9e83ced5e30378babd672bcda7921 (diff)
downloadopenttd-5c9acdb1825b699f9d796b06df728429e0b8a87e.tar.xz
(svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
-rw-r--r--newgrf.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/newgrf.c b/newgrf.c
index c9e0eae42..60d94731b 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -1014,29 +1014,27 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
Bridge *bridge = &_bridge[brid + i];
byte tableid = grf_load_byte(&buf);
byte numtables = grf_load_byte(&buf);
- byte table, sprite;
if (bridge->sprite_table == NULL) {
- /* Allocate memory for sprite table pointers and set to NULL */
- bridge->sprite_table = malloc(7 * sizeof(*bridge->sprite_table));
- for (table = 0; table < 7; table++)
- bridge->sprite_table[table] = NULL;
+ /* Allocate memory for sprite table pointers and zero out */
+ bridge->sprite_table = calloc(7, sizeof(*bridge->sprite_table));
}
- for (table = tableid; table < tableid + numtables; table++) {
- if (table < 7) {
- if (bridge->sprite_table[table] == NULL) {
- bridge->sprite_table[table] = malloc(32 * sizeof(**bridge->sprite_table));
- }
+ for (; numtables-- != 0; tableid++) {
+ byte sprite;
- 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);
+ if (tableid >= 7) { // skip invalid data
+ grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", tableid);
+ for (sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf);
+ continue;
}
+
+ if (bridge->sprite_table[tableid] == NULL) {
+ bridge->sprite_table[tableid] = malloc(32 * sizeof(**bridge->sprite_table));
+ }
+
+ for (sprite = 0; sprite < 32; sprite++)
+ bridge->sprite_table[tableid][sprite] = grf_load_dword(&buf);
}
}
break;