Skip to content

Commit

Permalink
Prevent a possible segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
jonipol authored Feb 26, 2024
1 parent 865fd32 commit 0105196
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nav2_smac_planner/src/analytic_expansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ typename AnalyticExpansion<NodeT>::AnalyticExpansionNodes AnalyticExpansion<Node

// A move of sqrt(2) is guaranteed to be in a new cell
static const float sqrt_2 = std::sqrt(2.0f);
if (d < sqrt_2) {
return AnalyticExpansionNodes();
}

unsigned int num_intervals = static_cast<unsigned int>(std::floor(d / sqrt_2));

AnalyticExpansionNodes possible_nodes;
Expand Down Expand Up @@ -248,7 +252,8 @@ typename AnalyticExpansion<NodeT>::AnalyticExpansionNodes AnalyticExpansion<Node
if (!failure) {
// We found 'a' valid expansion. Now to tell if its a quality option...
const float max_cost = _search_info.analytic_expansion_max_cost;
if (*std::max_element(node_costs.begin(), node_costs.end()) > 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
Expand Down

0 comments on commit 0105196

Please sign in to comment.