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 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

This comment has been minimized.

Copy link
Contributor

@glx22 glx22 commented May 16, 2019

Please open a PR with your fix.

@PeterN

This comment has been minimized.

Copy link
Member

@PeterN PeterN commented May 16, 2019

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

@glx22

This comment has been minimized.

Copy link
Contributor

@glx22 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 added 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 added 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 LordAro closed this in d71a7c2 Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.