Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer dereference in ScriptOrder::GetOrderDistance in VT_AIR mode on waypoint tiles #7593

Closed
JGRennison opened this issue May 16, 2019 · 3 comments

Comments

@JGRennison
Copy link
Contributor

JGRennison commented May 16, 2019

Version of OpenTTD

Current master

Expected result

No null pointer dereference occurs when calling ScriptOrder::GetOrderDistance in VT_AIR mode with either origin_tile or dest_tile as a waypoint tile.

Actual result

Null pointer dereference occurs when calling ScriptOrder::GetOrderDistance in VT_AIR mode with either origin_tile or dest_tile as a waypoint tile.
ScriptTile::IsStationTile() (i.e. IsTileType(tile, MP_STATION)) returns true for waypoint tiles, however Station::GetByTile() returns nullptr.

Steps to reproduce

Load and unpause the attached savegame.
AIAI v97 calls ScriptOrder::GetOrderDistance in VT_AIR on the west and north corners at initialisation.

GetOrderDistance bug.sav.zip

See also:
JGRennison/OpenTTD-patches@bdcafb3
Thread starting from: https://www.tt-forums.net/viewtopic.php?p=1221446#p1221446

@glx22
Copy link
Contributor

glx22 commented May 16, 2019

Please open a PR with your fix.

@PeterN
Copy link
Member

PeterN commented May 16, 2019

Wouldn't it make more sense for ScriptTile::IsStationTile() to return false for waypoints?

@glx22
Copy link
Contributor

glx22 commented May 16, 2019

ScriptTile::IsStationTile() only checks for MP_STATION. Adding && ::Station::GetByTile() != nullptr could work, but then we'd need to add ScriptTile::IsWaypointTile() with && ::Waypoint::GetByTile() != nullptr and an API compatibility function for the old behaviour in scripts.

JGRennison added a commit to JGRennison/Upstream-OpenTTD that referenced this issue May 23, 2019
Null pointer dereference occurred when either origin_tile or dest_tile
were waypoint tiles.
LordAro pushed a commit to JGRennison/Upstream-OpenTTD that referenced this issue Jul 7, 2019
Null pointer dereference occurred when either origin_tile or dest_tile
were waypoint tiles.
LordAro pushed a commit to JGRennison/Upstream-OpenTTD that referenced this issue Jul 7, 2019
Null pointer dereference occurred when either origin_tile or dest_tile
were waypoint tiles.
douiwby pushed a commit to douiwby/OpenTTD that referenced this issue Apr 16, 2020
Null pointer dereference occurred when either origin_tile or dest_tile
were waypoint tiles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants