Skip to content

Commit

Permalink
Fix possible infinite recursion in FMT_ASSERT (#1744)
Browse files Browse the repository at this point in the history
Use std::fprintf for assertion message output preventing infinite
recursion when output to stderr is limited or broken.
  • Loading branch information
tohammer authored Jul 1, 2020
1 parent cbddab2 commit 5de62af
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5de62af

Please sign in to comment.