Fix crash when stringifying pre 1970 dates on Windows

`gmtime*` on Windows fails on dates pre 1970, and because we didn't
check the return code, we would then pass invalid `tm` struct to
`strftime` causing it to assert.

Closes #2944
This commit is contained in:
Martin Hořeňovský committed 2025-01-05 16:04:38 +01:00
1 parent a3b67a3abe
commit b0d0aa43e6
2 files changed
+28 -1

No files matched your search

+5 -1
View File
@@ -634,7 +634,11 @@ struct ratio_string<std::milli> {
#ifdef _MSC_VER
std::tm timeInfo = {};
gmtime_s(&timeInfo, &converted);
const auto err = gmtime_s(&timeInfo, &converted);
if ( err ) {
return "gmtime from provided timepoint has failed. This "
"happens e.g. with pre-1970 dates using Microsoft libc";
}
#else
std::tm* timeInfo = std::gmtime(&converted);
#endif