Don't crash if flush fails during unwinding

This commit is contained in:
Victor Zverovich
2024-01-07 14:00:26 -08:00
parent c1d9e88402
commit dbdfc99fa1
3 changed files with 36 additions and 9 deletions
+13 -1
View File
@@ -176,6 +176,13 @@ FMT_END_NAMESPACE_STD
# define FMT_EXCEPTIONS 1
# endif
#endif
#if FMT_EXCEPTIONS
# define FMT_TRY try
# define FMT_CATCH(x) catch (x)
#else
# define FMT_TRY if (true)
# define FMT_CATCH(x) if (false)
#endif
// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings.
#if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && \
@@ -965,7 +972,12 @@ class iterator_buffer : public Traits, public buffer<T> {
: Traits(other),
buffer<T>(grow, data_, 0, buffer_size),
out_(other.out_) {}
~iterator_buffer() { flush(); }
~iterator_buffer() {
FMT_TRY { flush(); }
FMT_CATCH(...) {
// Don't crash if flush fails during unwinding.
}
}
auto out() -> OutputIt {
flush();
-8
View File
@@ -137,14 +137,6 @@ FMT_END_NAMESPACE
# endif
#endif
#if FMT_EXCEPTIONS
# define FMT_TRY try
# define FMT_CATCH(x) catch (x)
#else
# define FMT_TRY if (true)
# define FMT_CATCH(x) if (false)
#endif
#ifndef FMT_MAYBE_UNUSED
# if FMT_HAS_CPP17_ATTRIBUTE(maybe_unused)
# define FMT_MAYBE_UNUSED [[maybe_unused]]