From de6048f51773abbb0f9c7c60f48457b6484098e4 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 24 Jan 2024 13:51:15 +0100 Subject: [PATCH] libc: consistency of tv_sec when tv_nsec wraps The libc's internal calculation of the tv_sec and tv_nsec fields must be based on the same ms value. Otherwise, tv_sec is not always immediately incremented whenever tv_nsec wraps. For applications, this inconsistency can result in observed jumps in time. Fixes #5098 --- repos/libports/src/lib/libc/internal/rtc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repos/libports/src/lib/libc/internal/rtc.h b/repos/libports/src/lib/libc/internal/rtc.h index 0dcdd5539d..c78fd43a7e 100644 --- a/repos/libports/src/lib/libc/internal/rtc.h +++ b/repos/libports/src/lib/libc/internal/rtc.h @@ -116,7 +116,7 @@ struct Libc::Rtc : Vfs::Watch_response_handler msecs_since_rtc_update.value / 1000; result.tv_sec = _rtc_value + seconds_since_rtc_update; - result.tv_nsec = (current_msecs.value % 1000) * (1000*1000); + result.tv_nsec = (msecs_since_rtc_update.value % 1000) * (1000*1000); return result; }