Fix possible infinite recursion in FMT_ASSERT (#1744)

Use std::fprintf for assertion message output preventing infinite
recursion when output to stderr is limited or broken.
This commit is contained in:
Tobias Hammer 2020-07-01 17:28:27 +02:00 committed by GitHub
parent cbddab2fe2
commit 5de62af604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,7 +49,9 @@ FMT_BEGIN_NAMESPACE
namespace detail {
FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
print(stderr, "{}:{}: assertion failed: {}", file, line, message);
// Use unchecked std::fprintf to avoid triggering another assertion when
// writing to stderr fails
std::fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
// Chosen instead of std::abort to satisfy Clang in CUDA mode during device
// code pass.
std::terminate();