Skip to content

Commit

Permalink
Improve input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKutzner committed Nov 25, 2024
1 parent b6e7c2e commit e484c18
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/nigiri/routing/sanitize_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
namespace nigiri::routing {

inline void sanitize_query(query& q) {
if (q.max_travel_time_.count() <= 0 || q.max_travel_time_ > kMaxTravelTime) {
// Ensure upper bound required by algorithm is a valid duration
constexpr auto const kAdditionalRequiredTime = decltype(kMaxTravelTime){1};
static_assert(kMaxTravelTime + kAdditionalRequiredTime <=
decltype(kMaxTravelTime)::max());
if (q.max_travel_time_.count() < 0 || q.max_travel_time_ > kMaxTravelTime) {
q.max_travel_time_ = kMaxTravelTime;
}
}
Expand Down

0 comments on commit e484c18

Please sign in to comment.