From 52e33889dfd6860dc3b2a05c52a3568e9ffe6a59 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Wed, 24 Aug 2022 23:45:09 +0200 Subject: [PATCH] Protect can_step_taken_wrt_to_zoc against null terrain Using can_step_taken_wrt_to_zoc in the path finding code (through unit_can_move_to_tile) makes it possible that unseen tiles are passed to it. We should therefore not assume that the terrain of the tile is known. Closes #1315. --- common/movement.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/movement.cpp b/common/movement.cpp index 268199c662..24338877b4 100644 --- a/common/movement.cpp +++ b/common/movement.cpp @@ -511,8 +511,10 @@ bool can_step_taken_wrt_to_zoc(const struct unit_type *punittype, if (tile_city(src_tile) || tile_city(dst_tile)) { return true; } - if (terrain_has_flag(tile_terrain(src_tile), TER_NO_ZOC) - || terrain_has_flag(tile_terrain(dst_tile), TER_NO_ZOC)) { + const auto src_terrain = tile_terrain(src_tile); + const auto dst_terrain = tile_terrain(dst_tile); + if ((src_terrain && terrain_has_flag(src_terrain, TER_NO_ZOC)) + || (dst_terrain && terrain_has_flag(dst_terrain, TER_NO_ZOC))) { return true; }