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

Odin undefined behaviour: handle case when xedgeuse is not initialized #3020

Merged
merged 2 commits into from
Apr 20, 2021

Conversation

merkispavel
Copy link
Contributor

Issue

There real world cases when xedge is not initialized after GetStraightestTraversableIntersectingEdgeTurnDegree call, i.e if the list is intersecting edge_size = 0

for (int i = 0; i < intersecting_edge_size(); ++i) {

Tasklist

  • Add tests
  • Add #fixes with the issue number that this PR addresses
  • Update the docs with any new request parameters or changes to behavior described
  • Update the changelog

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

@merkispavel merkispavel requested a review from dgearhart April 20, 2021 19:12
@merkispavel
Copy link
Contributor Author

merkispavel commented Apr 20, 2021

@dgearhart I have not ideas how to test it as this variable isn't visible outside IsPedestrianFork function

@mandeepsandhu
Copy link
Contributor

@dgearhart I have not ideas how to test it as this variable isn't visible outside IsPedestrianFork function

Actually I have question - the way its written currently, nothing really sets xedge_use correct? GetStraightestTraversableIntersectingEdgeTurnDegree() will only set xedge_use if its not null, and since the caller - IsPedestrianFork(), never sets the pointer, it never gets used within it.

Previously, xedge_use had an undefined value, but GetStraightestTraversableIntersectingEdgeTurnDegree() could conditionally set it (eg if xedge->has_use == true). Now it seems it will never get set since its always initialized to nullptr when called in the context of IsPedestrianFork. Or am I missing somerthing?

Copy link
Contributor

@mandeepsandhu mandeepsandhu left a comment

Choose a reason for hiding this comment

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

Left a comment, more for my clarification

@merkispavel
Copy link
Contributor Author

merkispavel commented Apr 20, 2021

since the caller - IsPedestrianFork(), never sets the pointer, it never gets used within it

The caller does set the "pointer"(i.e pointer to boost::optional).

boost::optional<TripLeg_Use> xedge_use;
// xedgeuse is a valid variable so &xedgeuse != nullptr
GetStraightestTraversableIntersectingEdgeTurnDegree(...,..., &xedge_use);

Check out the difference with the following piece of code

boost::optional<TripLeg_Use>* xedge_use = nulltpr;
GetStraightestTraversableIntersectingEdgeTurnDegree(...,..., xedge_use); // xedgeuse is null obviously

@mandeepsandhu
Copy link
Contributor

since the caller - IsPedestrianFork(), never sets the pointer, it never gets used within it

The caller does set the "pointer"(i.e pointer to boost::optional).

boost::optional<TripLeg_Use> xedge_use;
// xedgeuse is a valid variable so &xedgeuse != nullptr
GetStraightestTraversableIntersectingEdgeTurnDegree(...,..., &xedge_use);

Check out the difference with the following piece of code

boost::optional<TripLeg_Use>* xedge_use = nulltpr;
GetStraightestTraversableIntersectingEdgeTurnDegree(...,..., xedge_use); // xedgeuse is null obviously

Yup, makes sense. Thanks for the explanation! 👍

@dgearhart
Copy link
Member

dgearhart commented Apr 20, 2021

@merkispavel I would at least run RAD (master vs. branch) with the following files:

bicycle_routes.txt
demo_routes.txt
de_benchmark_routes.txt
eu_roundabout_routes.txt
pedestrian_roundabout_routes.txt
pedestrian_routes.txt
roundabout_routes.txt
timed_access_routes.txt
timed_conditional_routes.txt
turn_lane_routes.txt

@merkispavel
Copy link
Contributor Author

@merkispavel I would at least run RAD (master vs. branch) with the following files:

bicycle_routes.txt
demo_routes.txt
de_benchmark_routes.txt
eu_roundabout_routes.txt
pedestrian_roundabout_routes.txt
pedestrian_routes.txt
roundabout_routes.txt
timed_access_routes.txt
timed_conditional_routes.txt
turn_lane_routes.txt

I RAD-tested the changes 🟢

@merkispavel merkispavel merged commit 0cc3538 into master Apr 20, 2021
@merkispavel merkispavel deleted the fix-uninitialized-edgeuse branch April 21, 2021 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants