mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r4429) - CodeChange[newgrf]: Action0, prop 0x0D. use calloc to allocate memory and zero it out and change the loop a little
This commit is contained in:
parent
88e0bab283
commit
5c9acdb182
32
newgrf.c
32
newgrf.c
@ -1014,29 +1014,27 @@ static bool BridgeChangeInfo(uint brid, int numinfo, int prop, byte **bufp, int
|
|||||||
Bridge *bridge = &_bridge[brid + i];
|
Bridge *bridge = &_bridge[brid + i];
|
||||||
byte tableid = grf_load_byte(&buf);
|
byte tableid = grf_load_byte(&buf);
|
||||||
byte numtables = grf_load_byte(&buf);
|
byte numtables = grf_load_byte(&buf);
|
||||||
byte table, sprite;
|
|
||||||
|
|
||||||
if (bridge->sprite_table == NULL) {
|
if (bridge->sprite_table == NULL) {
|
||||||
/* Allocate memory for sprite table pointers and set to NULL */
|
/* Allocate memory for sprite table pointers and zero out */
|
||||||
bridge->sprite_table = malloc(7 * sizeof(*bridge->sprite_table));
|
bridge->sprite_table = calloc(7, sizeof(*bridge->sprite_table));
|
||||||
for (table = 0; table < 7; table++)
|
|
||||||
bridge->sprite_table[table] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (table = tableid; table < tableid + numtables; table++) {
|
for (; numtables-- != 0; tableid++) {
|
||||||
if (table < 7) {
|
byte sprite;
|
||||||
if (bridge->sprite_table[table] == NULL) {
|
|
||||||
bridge->sprite_table[table] = malloc(32 * sizeof(**bridge->sprite_table));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (sprite = 0; sprite < 32; sprite++)
|
if (tableid >= 7) { // skip invalid data
|
||||||
bridge->sprite_table[table][sprite] = grf_load_dword(&buf);
|
grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", tableid);
|
||||||
} else {
|
for (sprite = 0; sprite < 32; sprite++) grf_load_dword(&buf);
|
||||||
grfmsg(GMS_WARN, "BridgeChangeInfo: Table %d >= 7, skipping.", table);
|
continue;
|
||||||
// Skip past invalid data.
|
|
||||||
for (sprite = 0; sprite < 32; sprite++)
|
|
||||||
grf_load_dword(&buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user