From 654e7e0d39c515612713c7426a30b2a219ae477a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20P=C3=B6ll=C3=A4nen?= Date: Tue, 27 Feb 2024 23:10:48 +0200 Subject: [PATCH] Prevent a possible segmentation fault (#4141) (#4147) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Prevent a possible segmentation fault #4141 Signed-off-by: Joni Pöllänen * Cleanup Signed-off-by: Joni Pöllänen --------- Signed-off-by: Joni Pöllänen --- nav2_smac_planner/src/analytic_expansion.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nav2_smac_planner/src/analytic_expansion.cpp b/nav2_smac_planner/src/analytic_expansion.cpp index 7c73fb91da..8dcc131435 100644 --- a/nav2_smac_planner/src/analytic_expansion.cpp +++ b/nav2_smac_planner/src/analytic_expansion.cpp @@ -179,16 +179,17 @@ typename AnalyticExpansion::AnalyticExpansionNodes AnalyticExpansiondistance(from(), to()); + // A move of sqrt(2) is guaranteed to be in a new cell + static const float sqrt_2 = std::sqrt(2.0f); + // If the length is too far, exit. This prevents unsafe shortcutting of paths // into higher cost areas far out from the goal itself, let search to the work of getting // close before the analytic expansion brings it home. This should never be smaller than // 4-5x the minimum turning radius being used, or planning times will begin to spike. - if (d > _search_info.analytic_expansion_max_length) { + if (d > _search_info.analytic_expansion_max_length || d < sqrt_2) { return AnalyticExpansionNodes(); } - // A move of sqrt(2) is guaranteed to be in a new cell - static const float sqrt_2 = std::sqrt(2.0f); unsigned int num_intervals = static_cast(std::floor(d / sqrt_2)); AnalyticExpansionNodes possible_nodes; @@ -248,7 +249,8 @@ typename AnalyticExpansion::AnalyticExpansionNodes AnalyticExpansion max_cost) { + auto max_cost_it = std::max_element(node_costs.begin(), node_costs.end()); + if (max_cost_it != node_costs.end() && *max_cost_it > max_cost) { // If any element is above the comfortable cost limit, check edge cases: // (1) Check if goal is in greater than max_cost space requiring // entering it, but only entering it on final approach, not in-and-out