Skip to content

Fix findWayPointIndicesForDurationAfterStart method when out of bounds - #3626

Merged
nbbrooks merged 7 commits into
moveit:mainfrom
XingxinHE:xingxin/fix_findWayPointIndices
Dec 14, 2025
Merged

nbbrooks merged 7 commits into
moveit:mainfrom
XingxinHE:xingxin/fix_findWayPointIndices

Conversation

@XingxinHE

Copy link
Copy Markdown
Contributor

Description

The fix is to address the bug raised in issue #3612 which causes UB. The change has been

  • clang-format/tidy with docker image moveit/moveit2:rolling-ci
  • run unit test with moveit_core/robot_trajectory/test/test_robot_trajectory.cpp

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

Misc.

Actually, the wording "Create tests, which fail without this PR" is not strictly correct. Without the fix, the unit tests will "pass", but it passes with undefined behavior. Meaning, all the EXPECT_xx after the call findWayPointIndicesForDurationAfterStart will be omitted and the google test doesn't actually check it. I once plan to use the EXPECT_EXIT but UB doesn't always result in a SIGSEGV.

In my perspective, I prefer the .at() over [index]. See the guideline. But I guess using .at( might cause a little bit performance degrade in real time control of robot? If we use the [index] approach, then the unit test should run with AddressSanitizer or something. Since I am not quite familiar with the CI/CD of moveit2, therefore I defer whether to keep current implementation or change to .at() to @nbbrooks .

@XingxinHE

XingxinHE commented Nov 29, 2025 •

Copy link
Copy Markdown
Contributor Author

Hey @nbbrooks , this pr is ready for review.

@codecov

codecov Bot commented Nov 29, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.03%. Comparing base (9fba743) to head (42600d9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3626      +/-   ##
==========================================
- Coverage   46.24%   46.03%   -0.20%     
==========================================
  Files         726      726              
  Lines       59430    59492      +62     
  Branches     7625     7623       -2     
==========================================
- Hits        27477    27381      -96     
- Misses      31787    31945     +158     
  Partials      166      166              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nbbrooks nbbrooks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is looking good considering the unclear intended behavior from the original function description and the current [old] error handling patterns in the codebase. As I see it, the expected output with edge cases should be:

// If waypoints are empty: before == 0, after == 0, blend == 0 (invalid - empty trajectory)
// If target duration < 0: before == 0, after == 0, blend == 0 (invalid - before trajectory has started)
// If target duration > total duration of waypoints, before == size() - 1, after == size() - 1, blend == 1 (after trajectory has completed)
// If 1 waypoint and target duration == total duration of waypoints, before == 0, after == 0, blend == 1 (at single point trajectory completion)
// Else before == last waypoint index with total duration < target duration, after == before + 1, blend == fraction of target duration between total duration @ before and total duration @ after
//   Therefore, if 2 waypoints and target duration == total duration of waypoints, before == 0, after == 1, blend == 1 (at trajectory completion)

Since you are being so thorough, here are the last changes I suggest:

  1. Change access to use at() as you noted. I would not expect this to be in a real-time loop or have significant impact.
  2. Consider updating your test names to be more descriptive of the corner case they are checking (my suggestions are RobotTrajectoryFindWayPointIndicesBetweenWaypoints, RobotTrajectoryFindWayPointIndicesAtLastOfManyWaypoints, RobotTrajectoryFindWayPointIndicesAfterLastWaypoint, and RobotTrajectoryFindWayPointIndicesEmptyWaypoints)
  3. Add two more tests to check the remaining cases: RobotTrajectoryFindWayPointIndicesBeforeFirstWaypoint and RobotTrajectoryFindWayPointIndicesAtLastOfSingleWaypoint or something to that effect.

@XingxinHE

Copy link
Copy Markdown
Contributor Author

Nice! Then I change the unit test to use EXPECT_NO_THROW and future mistakes will be caught. I've updated the tests and docs as well.

@XingxinHE
XingxinHE requested a review from nbbrooks November 30, 2025 08:47

@nbbrooks nbbrooks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@XingxinHE

Copy link
Copy Markdown
Contributor Author

Thank you Nathan for the code review! I learned a lot.

@nbbrooks
nbbrooks enabled auto-merge (squash) December 14, 2025 16:50
@nbbrooks
nbbrooks merged commit 4287c80 into moveit:main Dec 14, 2025
@github-project-automation github-project-automation Bot moved this to ✅ Done in MoveIt Dec 14, 2025
@130s 130s added the backport-jazzy Mergify label that triggers a PR backport to Jazzy label Sep 25, 2026
nbbrooks added a commit that referenced this pull request Oct 26, 2026
#3626) (#3874)

* Fix findWayPointIndicesForDurationAfterStart method when out of bounds and add unit tests

* Use .at() to index deque; Add 2 more edge test cases

* Revise function comments

---------



(cherry picked from commit 4287c80)

Co-authored-by: Xingxin HE <[email protected]>
Co-authored-by: Nathan Brooks <[email protected]>
Co-authored-by: Ezra Brooks <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-jazzy Mergify label that triggers a PR backport to Jazzy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants