Skip to content

Commit

Permalink
test: lib: exception_utils: fix crash with fmt-6.2.0
Browse files Browse the repository at this point in the history
fmt, the formatting library we use, detects types with conversion
to std::string_view (and formats them as strings) and types that
support operator<<(std::ostream, const T&) (and performs custom
formatting on them). However, if <fmt/ostream.h>, the latter is
not done.

The problem happens with seastar::sstring, which implements both,
and debug mode, which disables inlining. Some translation units
do include <fmt/ostream.h>, and so generate code to do custom
formatting. exception_utils.cc doesn't, and so generates code
to format via string_view conversion. At link time, the
compiler picks one of the generated functions and includes it
in the final binary; it happened to pick one generated outside
exception_utils.cc, using custom formatting.

However, there is also code in fmt to encode which path fmt
chose - string_view or custom. This code is constexpr and so
is evaluated in exception_utils.cc. The result is that the
function to perform formatting of seastar::sstring uses custom
formatting, while the descriptor containing the method used
says it is formatting via string_view. This is enough to cause
a crash.

The problem is limited to debug mode, since in other modes
all this code is inlined, and so is consistent within the
translation unit.

We need a more general fix (hopefully in fmt), but for now a
simple fix is to add the missing include.

Ref fmtlib/fmt#1662
  • Loading branch information
avikivity committed May 5, 2020
1 parent e44b282 commit 7fd6ae5
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions test/lib/exception_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <boost/test/unit_test.hpp>
#include <fmt/format.h>
#include <fmt/ostream.h>

std::function<bool(const std::exception&)> exception_predicate::make(
std::function<bool(const std::exception&)> check,
Expand Down

0 comments on commit 7fd6ae5

Please sign in to comment.