Skip to content

Commit

Permalink
Fix index out of range for stop_times last arrival of multi-section r…
Browse files Browse the repository at this point in the history
…un (#704)

* fix index out of range for stop_times last arrival of multi-section run

* follow style guide

Co-authored-by: Felix Gündling <felix.guendling@gmail.com>

---------

Co-authored-by: Felix Gündling <felix.guendling@gmail.com>
  • Loading branch information
traines-source and felixguendling authored Jan 18, 2025
1 parent 80c2d7c commit 3c361bb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/motis/tag_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ struct tag_lookup {
nigiri::source_idx_t get_src(std::string_view tag) const;
std::string_view get_tag(nigiri::source_idx_t) const;
std::string id(nigiri::timetable const&, nigiri::location_idx_t) const;
std::string id(nigiri::timetable const&, nigiri::rt::run_stop) const;
std::string id(nigiri::timetable const&,
nigiri::rt::run_stop,
nigiri::event_type) const;
nigiri::location_idx_t get_location(nigiri::timetable const&,
std::string_view) const;
std::pair<nigiri::rt::run, nigiri::trip_idx_t> get_trip(
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/stop_times.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ api::stoptimes_response stop_times::operator()(
.routeColor_ = to_str(s.get_route_color(ev_type).color_),
.routeTextColor_ =
to_str(s.get_route_color(ev_type).text_color_),
.tripId_ = tags_.id(tt_, s),
.tripId_ = tags_.id(tt_, s, ev_type),
.routeShortName_ = std::string{s.trip_display_name(ev_type)},
.source_ = fmt::format("{}", fmt::streamed(fr.dbg()))};
}),
Expand Down
2 changes: 1 addition & 1 deletion src/journey_to_response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ api::Itinerary journey_to_response(osr::ways const* w,
.agencyName_ = {std::string{agency.long_name_}},
.agencyUrl_ = {std::string{agency.url_}},
.agencyId_ = {std::string{agency.short_name_}},
.tripId_ = tags.id(tt, enter_stop),
.tripId_ = tags.id(tt, enter_stop, n::event_type::kDep),
.routeShortName_ = {std::string{
enter_stop.trip_display_name()}},
.source_ = fmt::to_string(fr.dbg())});
Expand Down
2 changes: 1 addition & 1 deletion src/railviz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ api::trips_response get_trains(tag_lookup const& tags,
[&](auto&& p) { enc.push(p); });

return {.trips_ = {api::TripInfo{
.tripId_ = tags.id(tt, from),
.tripId_ = tags.id(tt, from, n::event_type::kDep),
.routeShortName_ =
std::string{from.trip_display_name(n::event_type::kDep)}}},
.routeColor_ =
Expand Down
5 changes: 3 additions & 2 deletions src/tag_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ std::string tag_lookup::id(nigiri::timetable const& tt,
}

std::string tag_lookup::id(nigiri::timetable const& tt,
n::rt::run_stop s) const {
n::rt::run_stop s,
n::event_type const ev_type) const {
if (s.fr_->is_scheduled()) {
// trip id
auto const t = s.get_trip_idx(n::event_type::kDep);
auto const t = s.get_trip_idx(ev_type);
auto const id_idx = tt.trip_ids_[t].front();
auto const id = tt.trip_id_strings_[id_idx].view();
auto const src = tt.trip_id_src_[id_idx];
Expand Down

0 comments on commit 3c361bb

Please sign in to comment.