mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-24 11:35:31 +08:00
libstdc++: Improve overflow check for file timestamps
The current code assumes that system_clock::duration is nanoseconds, and also performs a value-changing conversion from nanoseconds::max() to double (which doesn't matter after dividing by 1e9, but triggers a warning with Clang nonetheless). A better solution is to use system_clock::duration::max() and perform the comparison entirely using the std::chrono types, rather than with dimensionless arithmetic types. This doesn't address the FIXME in the function, so the overflow check still rejects some values that could be represented by the file_clock. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * src/filesystem/ops-common.h (filesystem::file_time): Improve overflow check by using system_clock::duration::max().
This commit is contained in:
parent
c8a1cf1a7a
commit
65441d8fc3
@ -229,7 +229,7 @@ namespace __gnu_posix
|
||||
// (This only applies to the C++17 Filesystem library, because for the
|
||||
// Filesystem TS we don't have a distinct __file_clock, we just use the
|
||||
// system clock for file timestamps).
|
||||
if (s >= (nanoseconds::max().count() / 1e9))
|
||||
if (seconds{s} >= floor<seconds>(system_clock::duration::max()))
|
||||
{
|
||||
ec = std::make_error_code(std::errc::value_too_large); // EOVERFLOW
|
||||
return system_clock::time_point::min();
|
||||
|
Loading…
Reference in New Issue
Block a user