mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Use str_format_v
for log_log_impl
Reduces duplicate code. This also ensures that the log messages are properly zero-terminated and that they do not end with truncated unicode characters.
This commit is contained in:
parent
854445d4e1
commit
baa448580a
|
@ -73,6 +73,10 @@ void log_set_scope_logger(ILogger *logger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Separate declaration, as attributes are not allowed on function definitions
|
||||||
|
void log_log_impl(LEVEL level, bool have_color, LOG_COLOR color, const char *sys, const char *fmt, va_list args)
|
||||||
|
GNUC_ATTRIBUTE((format(printf, 5, 0)));
|
||||||
|
|
||||||
void log_log_impl(LEVEL level, bool have_color, LOG_COLOR color, const char *sys, const char *fmt, va_list args)
|
void log_log_impl(LEVEL level, bool have_color, LOG_COLOR color, const char *sys, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
if(level > loglevel.load(std::memory_order_acquire))
|
if(level > loglevel.load(std::memory_order_acquire))
|
||||||
|
@ -109,18 +113,7 @@ void log_log_impl(LEVEL level, bool have_color, LOG_COLOR color, const char *sys
|
||||||
|
|
||||||
char *pMessage = Msg.m_aLine + Msg.m_LineMessageOffset;
|
char *pMessage = Msg.m_aLine + Msg.m_LineMessageOffset;
|
||||||
int MessageSize = sizeof(Msg.m_aLine) - Msg.m_LineMessageOffset;
|
int MessageSize = sizeof(Msg.m_aLine) - Msg.m_LineMessageOffset;
|
||||||
#ifdef __GNUC__
|
str_format_v(pMessage, MessageSize, fmt, args);
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
||||||
#endif
|
|
||||||
#if defined(CONF_FAMILY_WINDOWS)
|
|
||||||
_vsprintf_p(pMessage, MessageSize, fmt, args);
|
|
||||||
#else
|
|
||||||
vsnprintf(pMessage, MessageSize, fmt, args);
|
|
||||||
#endif
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
Msg.m_LineLength = str_length(Msg.m_aLine);
|
Msg.m_LineLength = str_length(Msg.m_aLine);
|
||||||
scope_logger->Log(&Msg);
|
scope_logger->Log(&Msg);
|
||||||
in_logger = false;
|
in_logger = false;
|
||||||
|
|
Loading…
Reference in a new issue