Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent a possible segmentation fault (#4141) #4147

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to the if statement above

if (d > _search_info.analytic_expansion_max_length || d < sqrt_2) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ that would require moving the sqrt_2 definition above as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for feedback!

return AnalyticExpansionNodes();

Check warning on line 193 in nav2_smac_planner/src/analytic_expansion.cpp

View check run for this annotation

Codecov / codecov/patch

nav2_smac_planner/src/analytic_expansion.cpp#L193

Added line #L193 was not covered by tests
}

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

AnalyticExpansionNodes possible_nodes;
Expand Down Expand Up @@ -248,7 +252,8 @@
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
Loading