From 400dd427808629913b82e9c23db1a0092d542b9e Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Mon, 22 Aug 2016 18:46:37 +0200 Subject: [PATCH] fix segmentation fault for via-routes with invalid intermediate segments --- CHANGELOG.md | 5 +++ features/testbot/via.feature | 32 +++++++++++++++++++ .../routing_algorithms/shortest_path.hpp | 6 +++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abf332670..e823b7a05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 5.3.3 + Changes from 5.3.2 + - Bugfixes + - Fixed an issue that would result in segfaults for viaroutes with an invalid intermediate segment when u-turns were allowed at the via-location + # 5.3.2 Changes from 5.3.1 - Bugfixes diff --git a/features/testbot/via.feature b/features/testbot/via.feature index 08a684a5d..a82334615 100644 --- a/features/testbot/via.feature +++ b/features/testbot/via.feature @@ -262,3 +262,35 @@ Feature: Via points | 3,2,1 | ab,bc,cd,da,ab,ab,ab,bc,cd,da,ab,ab | 3000m +-1 | | 6,5,4 | bc,cd,da,ab,bc,bc,bc,cd,da,ab,bc,bc | 3000m +-1 | | 9,8,7 | cd,da,ab,bc,cd,cd,cd,da,ab,bc,cd,cd | 3000m +-1 | + + # See issue #2706 + Scenario: Incorrect ordering of nodes can produce multiple U-turns + Given the node map + | | a | | | | + | e | b | c | d | f | + + And the ways + | nodes | oneway | + | abcd | no | + | ebbdcf | yes | + + When I route I should get + | from | to | route | + | e | f | ebbdcf,ebbdcf | + + @2798 + Scenario: UTurns Enabled + Given the node map + | a | b | c | d | e | + + And the query options + | continue_straight | false | + + And the ways + | nodes | oneway | + | abc | yes | + | edc | yes | + + When I route I should get + | waypoints | route | + | a,b,e | | diff --git a/include/engine/routing_algorithms/shortest_path.hpp b/include/engine/routing_algorithms/shortest_path.hpp index 5d52dc934..c0a338b19 100644 --- a/include/engine/routing_algorithms/shortest_path.hpp +++ b/include/engine/routing_algorithms/shortest_path.hpp @@ -114,7 +114,11 @@ class ShortestPathRouting final needs_loop_forwad, needs_loop_backwards); } - new_total_distance += std::min(total_distance_to_forward, total_distance_to_reverse); + // if no route is found between two parts of the via-route, the entire route becomes + // invalid. Adding to invalid edge weight sadly doesn't return an invalid edge weight. Here + // we prevent the possible overflow, faking the addition of infinity + x == infinity + if (new_total_distance != INVALID_EDGE_WEIGHT) + new_total_distance += std::min(total_distance_to_forward, total_distance_to_reverse); } // searches shortest path between: