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
Conversation
…creation this shortcut (fences haven't changed, so don't bother retrying) wasn't setting the passing-in error ID, leading to use of unininitialised stack data. So remember the error ID and return it in this case
@@ -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); |
There was a problem hiding this comment.
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
On Sun, 21 Jan 2024, Tom Pittenger wrote:
In libraries/AC_Avoidance/AP_OADijkstra.h:
> @@ -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);
identiacally-named functions like this a ripe for confusion
There's already a comment to dispel that confusion.
If you want to nominate a replacement method name.....
|
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; |
There was a problem hiding this comment.
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?
My solution would be to add a _last_error_id variable and pass that back in this one case. The slightly annoying part of my suggestion is that it means we'd need to set this _last_error_id everywhere we set err_id... so if you think you have a better idea then looking forward to it. |
On Mon, 22 Jan 2024, Randy Mackay wrote:
My preferred solution would be to add a _last_error_id variable and pass that back in this one case. The slightly annoying part of my suggestion is that it means we'd need to set this _last_error_id
everywhere we set err_id... so if you think you have a better idea then looking forward to it.
This *was* by better idea - record the error code in a wrapper function
:-)
|
…creation
this shortcut (fences haven't changed, so don't bother retrying) wasn't setting the passing-in error ID, leading to use of unininitialised stack data.
So remember the error ID and return it in this case