From df3c8267d41d5caebd769d246ef70c85a16029e7 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 2 Aug 2020 16:45:53 -0600 Subject: [PATCH] AK: Fix adding timeval/timespec tv_usec and tv_nsec should always be less than one second. --- AK/Time.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/Time.h b/AK/Time.h index 7f65bfa7ae6..e29229d19e4 100644 --- a/AK/Time.h +++ b/AK/Time.h @@ -44,7 +44,7 @@ inline void timeval_add(const TimevalType& a, const TimevalType& b, TimevalType& { result.tv_sec = a.tv_sec + b.tv_sec; result.tv_usec = a.tv_usec + b.tv_usec; - if (result.tv_usec > 1'000'000) { + if (result.tv_usec >= 1'000'000) { ++result.tv_sec; result.tv_usec -= 1'000'000; } @@ -66,7 +66,7 @@ inline void timespec_add(const TimespecType& a, const TimespecType& b, TimespecT { result.tv_sec = a.tv_sec + b.tv_sec; result.tv_nsec = a.tv_nsec + b.tv_nsec; - if (result.tv_nsec > 1000'000'000) { + if (result.tv_nsec >= 1000'000'000) { ++result.tv_sec; result.tv_nsec -= 1000'000'000; }