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ý
2025-01-05 01:27:43 +01:00
parent a3b67a3abe
commit b0d0aa43e6
2 changed files with 28 additions and 1 deletions

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