From 01051962ac773cbfa6fcba8d0df0eb87683c63a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20P=C3=B6ll=C3=A4nen?= Date: Mon, 26 Feb 2024 15:30:41 +0200 Subject: [PATCH] Prevent a possible segmentation fault #4141 --- nav2_smac_planner/src/analytic_expansion.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nav2_smac_planner/src/analytic_expansion.cpp b/nav2_smac_planner/src/analytic_expansion.cpp index 7c73fb91da7..93026f64aa3 100644 --- a/nav2_smac_planner/src/analytic_expansion.cpp +++ b/nav2_smac_planner/src/analytic_expansion.cpp @@ -189,6 +189,10 @@ typename AnalyticExpansion::AnalyticExpansionNodes AnalyticExpansion(std::floor(d / sqrt_2)); AnalyticExpansionNodes possible_nodes; @@ -248,7 +252,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