Skip to content

Commit

Permalink
prevent crash with the downsampling function
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime CLEMENT <[email protected]>
  • Loading branch information
maxime-clem committed Jun 27, 2024
1 parent 228b6af commit c1434b7
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <autoware_planning_msgs/msg/trajectory_point.hpp>

#include <algorithm>
#include <vector>

namespace autoware::motion_velocity_planner
Expand All @@ -31,12 +32,12 @@ std::vector<autoware_planning_msgs::msg::TrajectoryPoint> downsample_trajectory(
const std::vector<autoware_planning_msgs::msg::TrajectoryPoint> & trajectory,
const size_t start_idx, const size_t end_idx, const int factor)
{
if (factor < 1) {
if (factor < 1 || end_idx <= start_idx) {
return trajectory;
}
std::vector<autoware_planning_msgs::msg::TrajectoryPoint> downsampled_traj;
downsampled_traj.reserve((end_idx - start_idx) / factor + 1);
for (size_t i = start_idx; i <= end_idx; i += factor) {
for (size_t i = start_idx; i < std::min(trajectory.size(), end_idx + 1); i += factor) {
downsampled_traj.push_back(trajectory[i]);
}
return downsampled_traj;
Expand Down

0 comments on commit c1434b7

Please sign in to comment.