Skip to content

Commit

Permalink
Check for index in path node list when parsing connection
Browse files Browse the repository at this point in the history
We had an issue when the data got corrupted and the number of entry in the path was not the same
as in the schedule. This was corrupting the memory.
We use the at() instead of [] when accessing the vector in the parsing loop in
getSchedules() and we display a meaningful error message if we
get the exceptiono
  • Loading branch information
greenscientist committed Jun 11, 2024
1 parent 88c3b58 commit ed0fcf7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/trips_and_connections_cache_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ namespace TrRouting
for (unsigned long nodeTimeI = 0; nodeTimeI < nodeTimesCount - 1; nodeTimeI++)
{

try {
connections.push_back(Connection(
path.nodesRef[nodeTimeI].get(),
path.nodesRef[nodeTimeI + 1].get(),
path.nodesRef.at(nodeTimeI).get(),
path.nodesRef.at(nodeTimeI + 1).get(),
departureTimesSeconds[nodeTimeI],
arrivalTimesSeconds[nodeTimeI + 1],
trip,
Expand All @@ -116,7 +117,10 @@ namespace TrRouting
));

trip.connectionDepartureTimes[nodeTimeI] = departureTimesSeconds[nodeTimeI];

} catch (std::out_of_range const& exc) {
spdlog::error("Index out of range while parsing connection for trip on line ({})", path.line.longname);
return -1;
}
}
}
}
Expand Down

0 comments on commit ed0fcf7

Please sign in to comment.