From bf4499c64316cd9272511138e1d0afd157abf15e Mon Sep 17 00:00:00 2001 From: peter1138 Date: Tue, 4 Apr 2017 00:00:43 +0000 Subject: (svn r27846) -Fix [FS#5926]: Infinite loop in pathfinder when checking safe waiting position from a waypoint. --- src/pathfinder/yapf/yapf_costrail.hpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/pathfinder') diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index d9d89b12f..22103987a 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -418,9 +418,16 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th CFollowTrackRail ft(v); TileIndex t = cur.tile; Trackdir td = cur.td; + /* Arbitrary maximum tiles to follow to avoid infinite loops. */ + uint max_tiles = 20; while (ft.Follow(t, td)) { assert(t != ft.m_new_tile); t = ft.m_new_tile; + if (t == cur.tile || --max_tiles == 0) { + /* We looped back on ourself or found another loop, bail out. */ + td = INVALID_TRACKDIR; + break; + } if (KillFirstBit(ft.m_new_td_bits) != TRACKDIR_BIT_NONE) { /* We encountered a junction; it's going to be too complex to * handle this perfectly, so just bail out. There is no simple -- cgit v1.2.3-70-g09d2