From e0d2c1308e7275e9fb4bbacb7ec4735d62e5f9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20B?= Date: Mon, 26 Feb 2024 06:43:29 +0100 Subject: [PATCH] log: fix SOC_U::Accept LOG_DEBUG call, and ensure such mistakes get picked up at compile time (#7463) * fix SOC_U::Accept invalid log function * make logging get checked at compile time - ensures log strings match the amount and type (if the format specifies an integer, for example) of the arguments - if at any later point a runtime-generated string is used as the log format, FmtLogMessage might require an overload taking a fmt::runtime_format_string<> as the format argument type, everything else being equal. wrap the generated string with fmt::runtime() before passing to the LOG_X function * formatting fix: aligning the arguments --- src/common/logging/backend.cpp | 2 +- src/common/logging/log.h | 4 ++-- src/core/hle/service/soc/soc_u.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 1ea126eaa..b33462472 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -451,7 +451,7 @@ void SetColorConsoleBackendEnabled(bool enabled) { } void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, - unsigned int line_num, const char* function, const char* format, + unsigned int line_num, const char* function, fmt::string_view format, const fmt::format_args& args) { if (!initialization_in_progress_suppress_logging) { Impl::Instance().PushEntry(log_class, log_level, filename, line_num, function, diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 59269af3e..f7033d5bb 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -24,12 +24,12 @@ constexpr const char* TrimSourcePath(std::string_view source) { /// Logs a message to the global logger, using fmt void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, - unsigned int line_num, const char* function, const char* format, + unsigned int line_num, const char* function, fmt::string_view format, const fmt::format_args& args); template void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, - const char* function, const char* format, const Args&... args) { + const char* function, fmt::format_string format, const Args&... args) { FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format, fmt::make_format_args(args...)); } diff --git a/src/core/hle/service/soc/soc_u.cpp b/src/core/hle/service/soc/soc_u.cpp index b69729553..810b4c41e 100644 --- a/src/core/hle/service/soc/soc_u.cpp +++ b/src/core/hle/service/soc/soc_u.cpp @@ -1014,8 +1014,8 @@ void SOC_U::Accept(Kernel::HLERequestContext& ctx) { ctr_addr_buf.resize(async_data->max_addr_len); } - LOG_DEBUG(Service_SOC, "called, pid={}, fd={}, ret={}", async_data->socket_handle, - static_cast(async_data->ret)); + LOG_DEBUG(Service_SOC, "called, pid={}, fd={}, ret={}", async_data->pid, + async_data->socket_handle, static_cast(async_data->ret)); IPC::RequestBuilder rb(ctx, 0x04, 2, 2); rb.Push(ResultSuccess);