diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-11-23 14:03:25 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2020-11-23 14:03:25 (GMT) |
commit | b4c994f69c6e62ab95a5746db237d0237bc87bc1 (patch) | |
tree | ff184e7a53b4809c5146addbc32eb45d89912a4a /Source/cmFileTime.cxx | |
parent | 4549027a09756d7421651bc8312e4619707f076d (diff) | |
download | CMake-b4c994f69c6e62ab95a5746db237d0237bc87bc1.zip CMake-b4c994f69c6e62ab95a5746db237d0237bc87bc1.tar.gz CMake-b4c994f69c6e62ab95a5746db237d0237bc87bc1.tar.bz2 |
cmFileTime: Fix overflow on time computation
On Windows, time starting point is Januray, 1st of 1601.
So computing number of nanoseconds from this date exceeds 64bit
capabilities.
Diffstat (limited to 'Source/cmFileTime.cxx')
-rw-r--r-- | Source/cmFileTime.cxx | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Source/cmFileTime.cxx b/Source/cmFileTime.cxx index 96c70fe..0606baf 100644 --- a/Source/cmFileTime.cxx +++ b/Source/cmFileTime.cxx @@ -24,13 +24,13 @@ bool cmFileTime::Load(std::string const& fileName) } # if CMake_STAT_HAS_ST_MTIM // Nanosecond resolution - this->NS = fst.st_mtim.tv_sec * NsPerS + fst.st_mtim.tv_nsec; + this->Time = fst.st_mtim.tv_sec * UtPerS + fst.st_mtim.tv_nsec; # elif CMake_STAT_HAS_ST_MTIMESPEC // Nanosecond resolution - this->NS = fst.st_mtimespec.tv_sec * NsPerS + fst.st_mtimespec.tv_nsec; + this->Time = fst.st_mtimespec.tv_sec * UtPerS + fst.st_mtimespec.tv_nsec; # else // Second resolution - this->NS = fst.st_mtime * NsPerS; + this->Time = fst.st_mtime * UtPerS; # endif #else // Windows version. Get the modification time from extended file attributes. @@ -41,10 +41,11 @@ bool cmFileTime::Load(std::string const& fileName) } // Copy the file time to the output location. - this->NS = (static_cast<NSC>(fdata.ftLastWriteTime.dwHighDateTime) << 32) | - static_cast<NSC>(fdata.ftLastWriteTime.dwLowDateTime); - // The file time resolution is 100 ns. - this->NS *= 100; + using uint64 = unsigned long long; + + this->Time = static_cast<TimeType>( + (uint64(fdata.ftLastWriteTime.dwHighDateTime) << 32) + + fdata.ftLastWriteTime.dwLowDateTime); #endif return true; } |