Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gmtime_r instead of gmtime when compiling for posixy platforms #2165

Merged
merged 1 commit into from Jan 27, 2021

Conversation

horenmar
Copy link
Member

Description

gmtime has the rather obvious problem of not being reentrant, and thus being rather unsafe to use. Catch2 does not support threads in its internals, but this is not enough to avoid the danger: if user uses gmtime inside the tested function, then our use of gmtime in the JUnit reporter will corrupt their state.

However, it took until C11 to get a standard alternative, which is gmtime_s, and which is only available under specific conditions (__STDC_WANT_LIB_EXT1__ has to be defined before the first inclusion of time.h). Instead we use gmtime_r, which while standardized only by C23, has been part of POSIX for ages.

While there are no nice compatibility guarantees for using gmtime_r, it should likely be compatible with all major supported non-Windows platforms.

GitHub Issues

Closes #2008

@horenmar horenmar added the Tweak label Jan 27, 2021
@horenmar horenmar self-assigned this Jan 27, 2021
@horenmar horenmar merged commit 2dbe63a into devel Jan 27, 2021
@horenmar horenmar deleted the devel-gmtime-fixup branch January 28, 2021 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new github CodeQL reports that catch makes use of a standard library function that is not thread-safe
1 participant