Fix: GetCargoTranslation could return out-of-bounds index for old-style NewGRF using cargo-slots.

This commit is contained in:
frosch 2021-01-10 15:10:03 +01:00 committed by frosch
parent 63288f80f3
commit 0078554d6a

View File

@ -91,7 +91,10 @@ uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
{
/* Pre-version 7 uses the 'climate dependent' ID in callbacks and properties, i.e. cargo is the cargo ID */
if (grffile->grf_version < 7 && !usebit) return cargo;
if (grffile->grf_version < 7 && !usebit) {
if (cargo >= CargoSpec::GetArraySize() || !CargoSpec::Get(cargo)->IsValid()) return CT_INVALID;
return cargo;
}
/* Other cases use (possibly translated) cargobits */