mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 13:19:51 -05:00
string(TIMESTAMP): Fix %s placeholder for year 2038 on Windows
`difftime` returns a `double`, so commit 6727270b75 (CMake: Extend
TIMESTAMP sub-commands with new unix time format specifier, 2016-02-16,
v3.6.0-rc1~338^2) cast it to `long` to get an integer result. However,
in the MSVC ABI, `long` is a 32-bit integer. Use an explicit 64-bit
integer type instead.
Fixes: #26716
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <ctime>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -275,7 +276,8 @@ std::string cmTimestamp::AddTimestampComponent(
|
|||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::to_string(static_cast<long int>(difftime(timeT, unixEpoch)));
|
return std::to_string(
|
||||||
|
static_cast<int64_t>(std::difftime(timeT, unixEpoch)));
|
||||||
}
|
}
|
||||||
case 'f': // microseconds
|
case 'f': // microseconds
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -660,7 +660,10 @@ add_RunCMake_test(return)
|
|||||||
add_RunCMake_test(SarifOutput)
|
add_RunCMake_test(SarifOutput)
|
||||||
add_RunCMake_test(separate_arguments)
|
add_RunCMake_test(separate_arguments)
|
||||||
add_RunCMake_test(set_property)
|
add_RunCMake_test(set_property)
|
||||||
add_RunCMake_test(string)
|
add_RunCMake_test(string
|
||||||
|
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
|
||||||
|
-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
|
||||||
|
)
|
||||||
add_RunCMake_test(test_include_dirs)
|
add_RunCMake_test(test_include_dirs)
|
||||||
add_RunCMake_test(BundleUtilities)
|
add_RunCMake_test(BundleUtilities)
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ run_cmake(JoinNoArgs)
|
|||||||
run_cmake(JoinNoVar)
|
run_cmake(JoinNoVar)
|
||||||
|
|
||||||
run_cmake(Timestamp)
|
run_cmake(Timestamp)
|
||||||
|
if(NOT CMAKE_SYSTEM_NAME STREQUAL "AIX" # FIXME: Needs 64-bit build
|
||||||
|
AND NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS" # FIXME: Needs 64-bit build
|
||||||
|
AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
|
||||||
|
CMAKE_SYSTEM_PROCESSOR MATCHES "^(hppa|parisc64|sparc|sparc64)$" # FIXME: 32-bit time_t?
|
||||||
|
)
|
||||||
|
)
|
||||||
|
run_cmake(Timestamp2038)
|
||||||
|
endif()
|
||||||
run_cmake(TimestampEmpty)
|
run_cmake(TimestampEmpty)
|
||||||
run_cmake(TimestampInvalid)
|
run_cmake(TimestampInvalid)
|
||||||
run_cmake(TimestampInvalid2)
|
run_cmake(TimestampInvalid2)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
^RESULT=2038-01-20 05:00:00.000000 Wednesday=Wed January=Jan 38 day=020 wd=3 week=03 w_iso=03 %I=05 epoch=2147576400 TZ=GMT tz=\+0000$
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
set(ENV{SOURCE_DATE_EPOCH} "2147576400")
|
||||||
|
string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S.%f %A=%a %B=%b %y day=%j wd=%w week=%U w_iso=%V %%I=%I epoch=%s TZ=%Z tz=%z" UTC)
|
||||||
|
message("RESULT=${RESULT}")
|
||||||
Reference in New Issue
Block a user