Skip to content

Commit

Permalink
fix: Don't let fmtlib exceptions crash the app
Browse files Browse the repository at this point in the history
When fmt arguments don't match the format string, fmt will throw an
exception, or terminate if we disable exceptions (which we do).  For
gcc11+, we tried intercepting these, but let's do it for all platform,
and let's not terminate ourselves, but insted print and log the error.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz committed Aug 28, 2024
1 parent 8699b96 commit 6c4d352
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/include/OpenImageIO/detail/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
# define FMT_EXCEPTIONS 0
#endif

// Redefining FMT_THROW to something benign seems to avoid some UB or possibly
// gcc 11+ compiler bug triggered by the definition of FMT_THROW in fmt 10.1+
// when FMT_EXCEPTIONS=0, which results in mangling SIMD math. This nugget
// below works around the problems for hard to understand reasons.
#if !defined(FMT_THROW) && !FMT_EXCEPTIONS && OIIO_GNUC_VERSION >= 110000
// Redefining FMT_THROW to print and log the error. This should only occur if
// we've made a mistake and mismatched a format string and its arguments.
// Hopefully this will help us track it down.
#if !defined(FMT_THROW) && !FMT_EXCEPTIONS
# define FMT_THROW(x) \
OIIO_ASSERT_MSG(0, "fmt exception: %s", (x).what()), std::terminate()
OIIO::print("fmt exception: {}", (x).what()), \
OIIO::errorfmt("fmt exception: {}", (x).what())
#endif

// Use the grisu fast floating point formatting for old fmt versions
Expand Down

0 comments on commit 6c4d352

Please sign in to comment.