Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-01-05 01:27:43 +0100
committerMartin Hořeňovský2025-01-05 16:04:38 +0100
commitb0d0aa43e6785f01e2dc4708c23fd8903de26c5c (patch)
tree3936f0ffbb497dffc3825375407e7298473f9b9d /src/catch2
parenta3b67a3abecd40804fbd702982f67962dffcc8aa (diff)
downloadcatch3-b0d0aa43e6785f01e2dc4708c23fd8903de26c5c.tar.gz
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
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/catch_tostring.hpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/catch2/catch_tostring.hpp b/src/catch2/catch_tostring.hpp
index 67a7c1d2..5f84196f 100644
--- a/src/catch2/catch_tostring.hpp
+++ b/src/catch2/catch_tostring.hpp
@@ -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