-
Notifications
You must be signed in to change notification settings - Fork 87
fix(autoware_trajectory): make the get_index function safe #568
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for contributing to the Autoware project! 🚧 If your pull request is in progress, switch it to draft mode. Please ensure:
|
return std::distance(bases_.begin(), std::lower_bound(bases_.begin(), bases_.end(), s, comp)) - | ||
1; | ||
const int32_t idx = | ||
std::distance(bases_.begin(), std::lower_bound(bases_.begin(), bases_.end(), s, comp)) - 1; |
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.
This still gives 0 - 1 = 18446744073709551615
as int32_t
, which causes narrow-conversion from uint64_t
to int32_t
.
static_cast<int64_t or int32_t>(std::distance(bases_.begin(), std::lower_bound(bases_.begin(), bases_.end(), s, comp)))
still causes narrowing-conversion, so there is no choice but to check if std::distance(bases_.begin(), std::lower_bound(bases_.begin(), bases_.end(), s, comp)) == 0
and return 0, otherwise subtract 1
.
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.
Perhaps we also need to fix this method too? 👀
autoware_core/common/autoware_interpolation/src/spline_interpolation.cpp
Lines 140 to 146 in a308984
Eigen::Index SplineInterpolation::get_index(const double & key) const | |
{ | |
const auto it = std::lower_bound(base_keys_.begin(), base_keys_.end(), key); | |
return std::clamp( | |
static_cast<int>(std::distance(base_keys_.begin(), it)) - 1, 0, | |
static_cast<int>(base_keys_.size()) - 2); | |
} |
...trajectory/include/autoware/trajectory/interpolator/detail/interpolator_common_interface.hpp
Outdated
Show resolved
Hide resolved
…lator/detail/interpolator_common_interface.hpp Co-authored-by: Junya Sasaki <[email protected]>
Description
The get_index function now returns values between 0 and size -1.
Related links
Parent Issue:
How was this PR tested?
Notes for reviewers
None.
Interface changes
None.
Effects on system behavior
None.