From 8906fa3bb7f3945cb12fedff40fc66182ed72ca3 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Tue, 30 Apr 2024 11:00:19 +1000 Subject: [PATCH 1/2] Fix an error where time travelling with no chrono tasks would cause a segmentation fault --- src/extension/ChronoController.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/extension/ChronoController.hpp b/src/extension/ChronoController.hpp index d39ea32fe..812c46c82 100644 --- a/src/extension/ChronoController.hpp +++ b/src/extension/ChronoController.hpp @@ -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); + 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; } From c1894242231b5537cf766c6f0081a6a5a44f8831 Mon Sep 17 00:00:00 2001 From: Trent Houliston Date: Tue, 30 Apr 2024 11:07:23 +1000 Subject: [PATCH 2/2] clang-tidy --- src/extension/ChronoController.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/ChronoController.hpp b/src/extension/ChronoController.hpp index 812c46c82..28ee8e908 100644 --- a/src/extension/ChronoController.hpp +++ b/src/extension/ChronoController.hpp @@ -116,7 +116,7 @@ namespace extension { } break; case message::TimeTravel::Action::NEAREST: { - clock::time_point nearest = + 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);