gulrak / filesystem

An implementation of C++17 std::filesystem for C++11 /C++14/C++17/C++20 on Windows, macOS, Linux and FreeBSD.
MIT License
1.31k stars 168 forks source link

Fix a Y2038 bug in timeToFILETIME #145

Closed CookiePLMonster closed 1 year ago

CookiePLMonster commented 2 years ago

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.

While this function is currently unused by ghc, it resides in a public header so someone could have relied on it.

This PR is a part of a mini-project dedicated to fixing Y2038 problems caused by this very code snippet. https://cookieplmonster.github.io/2022/02/17/year-2038-problem/

phprus commented 2 years ago

@CookiePLMonster, Please fix the compilation error in Mingw (AppVeyor CI).

[  5%] Building CXX object test/CMakeFiles/filesystem_test.dir/filesystem_test.cpp.obj
In file included from C:\projects\filesystem\test\filesystem_test.cpp:62:0:
C:/projects/filesystem/include/ghc/filesystem.hpp: In function 'void ghc::filesystem::detail::timeToFILETIME(time_t, FILETIME&)':
C:/projects/filesystem/include/ghc/filesystem.hpp:2245:37: error: conversion to 'ULONGLONG {aka long long unsigned int}' from 'long long int' may change the sign of the result [-Werror=sign-conversion]
     ull.QuadPart = (t * 10000000LL) + 116444736000000000LL;
                    ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cc1plus.exe: all warnings being treated as errors
gulrak commented 1 year ago

Thank you for the PR and sorry for the very long delay.