summaryrefslogtreecommitdiffstats
path: root/Source/cmFileTime.cxx
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-11-23 14:03:25 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-11-23 14:03:25 (GMT)
commitb4c994f69c6e62ab95a5746db237d0237bc87bc1 (patch)
treeff184e7a53b4809c5146addbc32eb45d89912a4a /Source/cmFileTime.cxx
parent4549027a09756d7421651bc8312e4619707f076d (diff)
downloadCMake-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.cxx15
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;
}