From ae1dcefc05fb933bb120c60386f35942c603ad97 Mon Sep 17 00:00:00 2001 From: taikitanaka3 <65527974+taikitanaka3@users.noreply.github.com> Date: Fri, 8 Jul 2022 15:18:03 +0900 Subject: [PATCH] fix(behavior_velocity_crosswalk): fix segfo at crosswalk is empty case (#1287) Note : range check for size_t (0 -1) is going to generate inf Signed-off-by: tanaka3 --- .../scene_module/crosswalk/scene_crosswalk.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp b/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp index 58a8f8ef0fb23..7b034374cfd12 100644 --- a/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp +++ b/planning/behavior_velocity_planner/src/scene_module/crosswalk/scene_crosswalk.cpp @@ -731,16 +731,18 @@ void CrosswalkModule::clampAttentionRangeByNeighborCrosswalks( boost::optional prev_crosswalk{boost::none}; boost::optional next_crosswalk{boost::none}; - for (size_t i = 0; i < crosswalks.size() - 1; ++i) { - const auto ll_front = crosswalks.at(i); - const auto ll_back = crosswalks.at(i + 1); + if (!crosswalks.empty()) { + for (size_t i = 0; i < crosswalks.size() - 1; ++i) { + const auto ll_front = crosswalks.at(i); + const auto ll_back = crosswalks.at(i + 1); - if (ll_front.id() == module_id_ && ll_back.id() != module_id_) { - next_crosswalk = ll_back; - } + if (ll_front.id() == module_id_ && ll_back.id() != module_id_) { + next_crosswalk = ll_back; + } - if (ll_front.id() != module_id_ && ll_back.id() == module_id_) { - prev_crosswalk = ll_front; + if (ll_front.id() != module_id_ && ll_back.id() == module_id_) { + prev_crosswalk = ll_front; + } } }