Common/Log: Check format strings

Helps with catching incorrect format strings.

PanicAlertFmt already uses FMT_STRING and fmt::make_args_checked.
This commit is contained in:
Léo Lam 2020-11-19 02:36:36 +01:00
parent 7e9a2dcc72
commit 47c91696ee
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
2 changed files with 9 additions and 8 deletions

View File

@ -76,13 +76,14 @@ enum LOG_LEVELS
static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID";
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
std::string_view format, const fmt::format_args& args);
fmt::string_view format, const fmt::format_args& args);
template <typename... Args>
void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
std::string_view format, const Args&... args)
template <typename S, typename... Args>
void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const S& format,
const Args&... args)
{
GenericLogFmtImpl(level, type, file, line, format, fmt::make_format_args(args...));
GenericLogFmtImpl(level, type, file, line, format,
fmt::make_args_checked<Args...>(format, args...));
}
void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...)
@ -136,11 +137,11 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
// fmtlib capable API
#define GENERIC_LOG_FMT(t, v, ...) \
#define GENERIC_LOG_FMT(t, v, format, ...) \
do \
{ \
if (v <= MAX_LOGLEVEL) \
Common::Log::GenericLogFmt(v, t, __FILE__, __LINE__, __VA_ARGS__); \
Common::Log::GenericLogFmt(v, t, __FILE__, __LINE__, FMT_STRING(format), ##__VA_ARGS__); \
} while (0)
#define ERROR_LOG_FMT(t, ...) \

View File

@ -81,7 +81,7 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con
}
void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line,
std::string_view format, const fmt::format_args& args)
fmt::string_view format, const fmt::format_args& args)
{
auto* instance = LogManager::GetInstance();
if (instance == nullptr)