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

AC_Avoidance: correct use of uninitialised value when retrying fence … #26035

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion libraries/AC_Avoidance/AP_OADijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ bool AP_OADijkstra::check_inclusion_polygon_updated() const

// create polygons inside the existing inclusion polygons
// returns true on success. returns false on failure and err_id is updated
bool AP_OADijkstra::create_inclusion_polygon_with_margin(float margin_cm, AP_OADijkstra_Error &err_id)
bool AP_OADijkstra::_create_inclusion_polygon_with_margin(float margin_cm, AP_OADijkstra_Error &err_id)
{
const AC_Fence *fence = AC_Fence::get_singleton();

Expand All @@ -324,6 +324,8 @@ bool AP_OADijkstra::create_inclusion_polygon_with_margin(float margin_cm, AP_OAD

// skip unnecessary retry to build inclusion polygon if previous fence points have not changed
if (_inclusion_polygon_update_ms == fence->polyfence().get_inclusion_polygon_update_ms()) {
// return the error code we returned last time we were called with this fence set:
err_id = last_create_inclusion_polygon_with_margin_error_id;
return false;
}

Expand Down Expand Up @@ -399,6 +401,12 @@ bool AP_OADijkstra::create_inclusion_polygon_with_margin(float margin_cm, AP_OAD
}
return true;
}
bool AP_OADijkstra::create_inclusion_polygon_with_margin(float margin_cm, AP_OADijkstra_Error &err_id)
{
const bool ret = _create_inclusion_polygon_with_margin(margin_cm, err_id);
last_create_inclusion_polygon_with_margin_error_id = err_id;
Copy link
Member

Choose a reason for hiding this comment

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

couldn't you pass this class variable in from the function that calls this? That is to say remove this:

AP_OADijkstra_Error error_id;

And use the class variable in its place. I don't think you would need any of the other changes?

return ret;
}

// check if exclusion polygons have been updated since create_exclusion_polygon_with_margin was run
// returns true if changed
Expand Down
4 changes: 4 additions & 0 deletions libraries/AC_Avoidance/AP_OADijkstra.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class AP_OADijkstra {
// create polygons inside the existing inclusion polygons
// returns true on success. returns false on failure and err_id is updated
bool create_inclusion_polygon_with_margin(float margin_cm, AP_OADijkstra_Error &err_id);
// create polygons inside the existing inclusion polygons
// returns true on success. returns false on failure and err_id is updated. This function is wrapped so we can remember the error ID.
bool _create_inclusion_polygon_with_margin(float margin_cm, AP_OADijkstra_Error &err_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

identiacally-named functions like this a ripe for confusion

AP_OADijkstra_Error last_create_inclusion_polygon_with_margin_error_id;

//
// exclusion polygon methods
Expand Down
Loading