From 6d16e3078eec94bcd96bc5a5c5cc4d3b36c5c4da Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Tue, 20 Feb 2024 22:44:36 +0100 Subject: [PATCH] common: minor fixing in core_log_va Signed-off-by: Tomasz Gromadzki --- src/core/log.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/core/log.c b/src/core/log.c index d6071476d35..b1b1bc37f47 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -214,16 +214,13 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, if (msg_len < 0) goto end; - if (errnum != NO_ERRNO) { + if ((size_t)msg_len < buf_len - 1 && errnum != NO_ERRNO) { + /* + * Ask for the error string right after the already printed + * message. + */ char *msg_ptr = buf + msg_len; size_t buf_len_left = buf_len - (size_t)msg_len; - - /* Check if the longest possible error string can fit */ - if (buf_len_left < _CORE_LOG_MAX_ERRNO_MSG) { - goto end; - } - - /* Ask for the error string */ /* * If it fails, the best thing to do is to at least pass * the log message as is. @@ -236,13 +233,11 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, * the CORE_LOG() macro it has to be done here again since it is not * performed in the case of the CORE_LOG_TO_LAST macro. Sorry. */ - if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) { + if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) goto end; - } - if (0 == Core_log_function) { + if (0 == Core_log_function) goto end; - } ((core_log_function *)Core_log_function)(Core_log_function_context, level, file_name, line_no, function_name, buf); @@ -257,8 +252,8 @@ core_log(enum core_log_level level, int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...) { char message[_CORE_LOG_MSG_MAXPRINT] = ""; - va_list arg; + va_list arg; va_start(arg, message_format); core_log_va(message, sizeof(message), level, errnum, file_name, line_no, function_name, message_format, arg);