Codechange: Use std::vector for NewGRF station platform layouts.
This avoids the need to custom memory management and additional members. This also resolves use-after-free if modifying copied layouts, so presumably nobody has ever done that.
This commit is contained in:
@@ -1109,13 +1109,13 @@ static inline byte *CreateMulti(byte *layout, int n, byte b)
|
||||
* @param plat_len The length of the platforms.
|
||||
* @param statspec The specification of the station to (possibly) get the layout from.
|
||||
*/
|
||||
void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
|
||||
void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
|
||||
{
|
||||
if (statspec != nullptr && statspec->lengths >= plat_len &&
|
||||
statspec->platforms[plat_len - 1] >= numtracks &&
|
||||
statspec->layouts[plat_len - 1][numtracks - 1]) {
|
||||
if (statspec != nullptr && statspec->layouts.size() >= plat_len &&
|
||||
statspec->layouts[plat_len - 1].size() >= numtracks &&
|
||||
!statspec->layouts[plat_len - 1][numtracks - 1].empty()) {
|
||||
/* Custom layout defined, follow it. */
|
||||
memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
|
||||
memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1].data(),
|
||||
plat_len * numtracks);
|
||||
return;
|
||||
}
|
||||
@@ -1124,9 +1124,9 @@ void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSp
|
||||
CreateSingle(layout, numtracks);
|
||||
} else {
|
||||
if (numtracks & 1) layout = CreateSingle(layout, plat_len);
|
||||
numtracks >>= 1;
|
||||
int n = numtracks >> 1;
|
||||
|
||||
while (--numtracks >= 0) {
|
||||
while (--n >= 0) {
|
||||
layout = CreateMulti(layout, plat_len, 4);
|
||||
layout = CreateMulti(layout, plat_len, 6);
|
||||
}
|
||||
|
Reference in New Issue
Block a user