From 014dbed50782cd88da20e775860f62184bc99487 Mon Sep 17 00:00:00 2001 From: yumeyao Date: Wed, 3 Mar 2021 14:18:16 +0800 Subject: [PATCH] Fix when arg size > 15 and named_arg is present. --- include/fmt/fmtlog.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/fmt/fmtlog.h b/include/fmt/fmtlog.h index d5b2e23e..b1492320 100644 --- a/include/fmt/fmtlog.h +++ b/include/fmt/fmtlog.h @@ -10,7 +10,7 @@ using namespace fmt; template struct basic_format_entry { protected: using char_type = typename Context::char_type; - using format_arg = fmt::detail::value; + using format_arg = typename basic_format_args::format_arg; using arg_destructor = void (*)(void *p); basic_string_view format_; @@ -62,8 +62,17 @@ template struct format_entry : basic_format template inline const typename basic_format_entry::format_arg* basic_format_entry::get_format_args() const { + union obfuscated_args { + const fmt::detail::value* values_; + const format_arg* args_; + intptr_t pointer_; // more efficient to add integer with size, as the compiler is able to avoid emitting branch + } args; auto& entry = static_cast&>(*this); - return &entry.arg_store_.data_.args_[entry.desc_ & fmt::detail::has_named_args_bit ? 1 : 0]; + args.values_ = entry.arg_store_.data_.args_; + if (entry.desc_ & fmt::detail::has_named_args_bit) { + args.pointer_ += (desc_ & fmt::detail::is_unpacked_bit) ? sizeof(*args.args_) : sizeof(*args.values_); + } + return args.args_; } //