Skip to content

Commit

Permalink
common: minor fixing in core_log_va
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
  • Loading branch information
grom72 committed Feb 26, 2024
1 parent cba93a0 commit 6d16e30
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 6d16e30

Please sign in to comment.