From 126ffd104e974203e20233bda91b89567f5f8dc8 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 15 Mar 2019 03:12:20 +0100 Subject: [PATCH] Fix #8873: null dereference when trying to place footpath. --- distribution/changelog.txt | 1 + src/openrct2/actions/FootpathSceneryPlaceAction.hpp | 6 +++--- src/openrct2/world/Footpath.cpp | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index aa498361f6..472b25afee 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,6 +1,7 @@ 0.2.2+ (in development) ------------------------------------------------------------------------ - Fix: [#5579] Network desync immediately after connecting. +- Fix: [#8873] Potential crash when placing footpaths. 0.2.2 (2019-03-13) ------------------------------------------------------------------------ diff --git a/src/openrct2/actions/FootpathSceneryPlaceAction.hpp b/src/openrct2/actions/FootpathSceneryPlaceAction.hpp index 7e7a3f7377..aee3269473 100644 --- a/src/openrct2/actions/FootpathSceneryPlaceAction.hpp +++ b/src/openrct2/actions/FootpathSceneryPlaceAction.hpp @@ -75,14 +75,14 @@ public: } auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8); - auto pathElement = tileElement->AsPath(); - - if (pathElement == nullptr) + if (tileElement == nullptr) { log_error("Could not find path element."); return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE); } + auto pathElement = tileElement->AsPath(); + // No change if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && pathElement->GetAddition() == _pathItemType && !(pathElement->IsBroken())) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 3795e43c5a..2dad1d9c03 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -112,11 +112,11 @@ static bool entrance_has_direction(TileElement* tileElement, int32_t direction) TileElement* map_get_footpath_element(int32_t x, int32_t y, int32_t z) { - TileElement* tileElement; - - tileElement = map_get_first_element_at(x, y); + TileElement* tileElement = map_get_first_element_at(x, y); do { + if (tileElement == nullptr) + break; if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->base_height == z) return tileElement; } while (!(tileElement++)->IsLastForTile());