Skip to content

Commit

Permalink
Fix an error where time travelling with no chrono tasks would cause a…
Browse files Browse the repository at this point in the history
… segmentation fault (#105)

When time travelling in NEAREST mode with no chrono tasks, the code
would try to dereference an empty list. Fix this to ensure it works when
no chrono tasks are present
  • Loading branch information
TrentHouliston authored Apr 30, 2024
1 parent 0440a9f commit 964efc8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/extension/ChronoController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,10 @@ namespace extension {

} break;
case message::TimeTravel::Action::NEAREST: {
auto next_task =
std::min_element(tasks.begin(), tasks.end(), [](const ChronoTask& a, const ChronoTask& b) {
return a.time < b.time;
});
clock::set_clock(std::min(next_task->time, travel.target), travel.rtf);
const clock::time_point nearest =
tasks.empty() ? travel.target
: std::min(travel.target, std::min_element(tasks.begin(), tasks.end())->time);
clock::set_clock(nearest, travel.rtf);
} break;
}

Expand Down

0 comments on commit 964efc8

Please sign in to comment.