From 08dada84565ea5f49127123e356c82a150626f3c Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 1 Feb 2021 14:57:34 +0000 Subject: util: Disallow negative mocktime Signed-off-by: practicalswift Github-Pull: #21043 Rebased-From: 3ddbf22ed179a2db733af4b521bec5d2b13ebf4b --- src/util/time.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/util') diff --git a/src/util/time.cpp b/src/util/time.cpp index e96972fe12..d130e4e4d4 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -18,7 +20,7 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); } -static std::atomic nMockTime(0); //!< For unit testing +static std::atomic nMockTime(0); //!< For testing int64_t GetTime() { @@ -46,6 +48,7 @@ template std::chrono::microseconds GetTime(); void SetMockTime(int64_t nMockTimeIn) { + Assert(nMockTimeIn >= 0); nMockTime.store(nMockTimeIn, std::memory_order_relaxed); } -- cgit v1.2.3