From 1344d44a5a2d55b4d89c546841c9ef9835534520 Mon Sep 17 00:00:00 2001 From: dkavolis <12998363+dkavolis@users.noreply.github.com> Date: Wed, 21 Jul 2021 23:47:17 +0100 Subject: [PATCH] check args on formatting --- example/example.cpp | 1 + include/spdlog/fmt/bin_to_hex.h | 2 +- include/spdlog/logger.h | 9 +++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 49e6495f..6ea548f1 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -23,6 +23,7 @@ void custom_flags_example(); #include "spdlog/spdlog.h" #include "spdlog/cfg/env.h" // support for loading levels from the environment variable +#include "spdlog/fmt/ostr.h" int main(int, char *[]) { diff --git a/include/spdlog/fmt/bin_to_hex.h b/include/spdlog/fmt/bin_to_hex.h index 45bc8f7d..7a94db7a 100644 --- a/include/spdlog/fmt/bin_to_hex.h +++ b/include/spdlog/fmt/bin_to_hex.h @@ -89,7 +89,7 @@ struct formatter> // parse the format string flags template - auto parse(ParseContext &ctx) -> decltype(ctx.begin()) + FMT_CONSTEXPR auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(); while (it != ctx.end() && *it != '}') diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 06173327..befe7321 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -282,7 +282,7 @@ protected: SPDLOG_TRY { memory_buf_t buf; - fmt::detail::vformat_to(buf, fmt::to_string_view(fmt), fmt::make_format_args(args...)); + fmt::detail::vformat_to(buf, fmt::to_string_view(fmt), fmt::make_args_checked(fmt, args...)); details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); log_it_(log_msg, log_enabled, traceback_enabled); } @@ -290,8 +290,9 @@ protected: } #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log_(source_loc loc, level::level_enum lvl, const wstring_view_t &fmt, Args &&...args) + template, + typename std::enable_if::value, Char>::type * = nullptr> + void log_(source_loc loc, level::level_enum lvl, const FormatString &fmt, Args &&...args) { bool log_enabled = should_log(lvl); bool traceback_enabled = tracer_.enabled(); @@ -303,7 +304,7 @@ protected: { // format to wmemory_buffer and convert to utf8 fmt::wmemory_buffer wbuf; - fmt::format_to(std::back_inserter(wbuf), fmt, std::forward(args)...); + fmt::detail::vformat_to(wbuf, fmt::wstring_view(fmt), fmt::make_args_checked(fmt, args...)); memory_buf_t buf; details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));