From 5de62af604a5ada7bb1de579227210423976b092 Mon Sep 17 00:00:00 2001 From: Tobias Hammer Date: Wed, 1 Jul 2020 17:28:27 +0200 Subject: [PATCH] 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. --- include/fmt/format-inl.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 5809adc8..d8c9c8a5 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -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();