diff options
author | Jonathan G Rennison <j.g.rennison@gmail.com> | 2019-05-23 22:40:34 +0100 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2019-07-22 20:26:36 +0100 |
commit | d71a7c21da27e5f99e48b8ad21b669d078932e35 (patch) | |
tree | 7992f96e3efeb469b0899c1bb1dad62f187a7b9f | |
parent | 5981ed248a9971ab3df683652fc6a0ec5a3fd11c (diff) | |
download | openttd-d71a7c21da27e5f99e48b8ad21b669d078932e35.tar.xz |
Fix #7593: Crash in ScriptOrder::GetOrderDistance in VT_AIR mode
Null pointer dereference occurred when either origin_tile or dest_tile
were waypoint tiles.
-rw-r--r-- | src/script/api/script_order.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index a72245d04..045968874 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -669,8 +669,14 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance) /* static */ uint ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile) { if (vehicle_type == ScriptVehicle::VT_AIR) { - if (ScriptTile::IsStationTile(origin_tile) && ::Station::GetByTile(origin_tile)->airport.tile != INVALID_TILE) origin_tile = ::Station::GetByTile(origin_tile)->airport.tile; - if (ScriptTile::IsStationTile(dest_tile) && ::Station::GetByTile(dest_tile)->airport.tile != INVALID_TILE) dest_tile = ::Station::GetByTile(dest_tile)->airport.tile; + if (ScriptTile::IsStationTile(origin_tile)) { + Station *orig_station = ::Station::GetByTile(origin_tile); + if (orig_station != nullptr && orig_station->airport.tile != INVALID_TILE) origin_tile = orig_station->airport.tile; + } + if (ScriptTile::IsStationTile(dest_tile)) { + Station *dest_station = ::Station::GetByTile(dest_tile); + if (dest_station != nullptr && dest_station->airport.tile != INVALID_TILE) dest_tile = dest_station->airport.tile; + } return ScriptMap::DistanceSquare(origin_tile, dest_tile); } else { |