Skip to content

Commit

Permalink
[transit][world_feed] Fix crashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatiana-yan authored and mesozoic-drones committed Mar 30, 2021
1 parent 639d866 commit 651aca1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions transit/transit_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ FrequencyIntervals::FrequencyIntervals(gtfs::Frequencies const & frequencies)
{
for (auto const & freq : frequencies)
{
CHECK_GREATER(freq.headway_secs, 0, ());
m_intervals.emplace(TimeInterval(freq.start_time, freq.end_time), freq.headway_secs);
if (freq.headway_secs > 0)
m_intervals.emplace(TimeInterval(freq.start_time, freq.end_time), freq.headway_secs);
else
LOG(LINFO, ("Bad headway_secs:", freq.headway_secs));
}
}

Expand Down
15 changes: 10 additions & 5 deletions transit/world_feed/world_feed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,11 @@ bool WorldFeed::FillRoutes()
continue;

auto const itAgencyHash = m_gtfsIdToHash[FieldIdx::AgencyIdx].find(route.agency_id);
CHECK(itAgencyHash != m_gtfsIdToHash[FieldIdx::AgencyIdx].end(), (route.agency_id));
if (itAgencyHash == m_gtfsIdToHash[FieldIdx::AgencyIdx].end())
{
LOG(LINFO, ("Unknown agency", route.agency_id));
continue;
}

auto const & agencyHash = itAgencyHash->second;
CHECK(!agencyHash.empty(), ("Empty hash for agency id:", route.agency_id));
Expand Down Expand Up @@ -927,7 +931,7 @@ std::optional<Direction> WorldFeed::ProjectStopsToShape(
CHECK(itStop != m_stops.m_data.end(), (stopId));
auto const & stop = itStop->second;

size_t const prevIdx = i == 0 ? (direction == Direction::Forward ? 0 : shape.size())
size_t const prevIdx = i == 0 ? (direction == Direction::Forward ? 0 : shape.size() - 1)
: stopsToIndexes[stopIds[i - 1]].back();
auto const [curIdx, pointInserted] =
PrepareNearestPointOnTrack(stop.m_point, prevPoint, prevIdx, direction, shape);
Expand Down Expand Up @@ -1932,12 +1936,13 @@ void WorldFeed::SplitLinesBasedData()

auto const edgeFirst = m_edges.m_data.at(
EdgeId(lineData.m_stopIds[firstStopIdx], lineData.m_stopIds[firstStopIdx + 1], lineId));
CHECK(!(edgeFirst.m_shapeLink.m_startIndex == 0 && edgeFirst.m_shapeLink.m_endIndex == 0),
());
if (edgeFirst.m_shapeLink.m_startIndex == 0 && edgeFirst.m_shapeLink.m_endIndex == 0)
continue;

auto const edgeLast = m_edges.m_data.at(
EdgeId(lineData.m_stopIds[lastStopIdx - 1], lineData.m_stopIds[lastStopIdx], lineId));
CHECK(!(edgeLast.m_shapeLink.m_startIndex == 0 && edgeLast.m_shapeLink.m_endIndex == 0), ());
if (edgeLast.m_shapeLink.m_startIndex == 0 && edgeLast.m_shapeLink.m_endIndex == 0)
continue;

lineInRegion.m_shapeLink.m_startIndex =
std::min(edgeFirst.m_shapeLink.m_startIndex, edgeLast.m_shapeLink.m_endIndex);
Expand Down

0 comments on commit 651aca1

Please sign in to comment.