From 4f0824fd766d53005ca615d7f1a327572705667e Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 22 May 2022 16:14:56 +0200 Subject: [PATCH] Fix a Y2038 bug in timeToFILETIME The old code truncated time_t to a 32-bit value when using Int32x32To64. This example code has been fixed on MSDN a while ago, so this change only updates it to the current version. More on this issue: https://cookieplmonster.github.io/2022/02/17/year-2038-problem/ --- include/ghc/filesystem.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 9540b44..485bd44 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -2241,10 +2241,10 @@ GHC_INLINE time_t timeFromFILETIME(const FILETIME& ft) GHC_INLINE void timeToFILETIME(time_t t, FILETIME& ft) { - LONGLONG ll; - ll = Int32x32To64(t, 10000000) + 116444736000000000; - ft.dwLowDateTime = static_cast(ll); - ft.dwHighDateTime = static_cast(ll >> 32); + ULARGE_INTEGER ull; + ull.QuadPart = static_cast((t * 10000000LL) + 116444736000000000LL); + ft.dwLowDateTime = ull.LowPart; + ft.dwHighDateTime = ull.HighPart; } template