Skip to content

Commit

Permalink
Fix OpenTTD#7593: Crash in ScriptOrder::GetOrderDistance in VT_AIR mode
Browse files Browse the repository at this point in the history
Null pointer dereference occurred when either origin_tile or dest_tile
were waypoint tiles.
  • Loading branch information
JGRennison authored and douiwby committed Apr 16, 2020
1 parent 1e42899 commit 429e295
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/script/api/script_order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 429e295

Please sign in to comment.