Skip to content

Commit

Permalink
解决LOG_RAW异步输出多条文本的时候会被截断,原因是rt_vsnprintf会在字符串最后添加\0,ulog.c中的do_output…
Browse files Browse the repository at this point in the history
…()将\0也压入到ulog.async_rb,当LOG_RAW没有及时输出,那么rb中的字符串被\0截断了,导致没法正确输出LOG_RAW信息
  • Loading branch information
ComerLater committed Apr 19, 2024
1 parent 61fac62 commit 05e5ec6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions components/utilities/ulog/ulog.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ static void do_output(rt_uint32_t level, const char *tag, rt_bool_t is_raw, cons
}
else if (ulog.async_rb)
{
rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, (rt_uint16_t)log_buf_size);
/* log_buf_size contain the tail \0, which will lead discard follow char, so only put log_buf_size -1 */
rt_ringbuffer_put(ulog.async_rb, (const rt_uint8_t *)log_buf, (rt_uint16_t)log_buf_size - 1);
/* send a notice */
rt_sem_release(&ulog.async_notice);
}
Expand Down Expand Up @@ -793,8 +794,11 @@ void ulog_raw(const char *format, ...)
fmt_result = rt_vsnprintf(log_buf, ULOG_LINE_BUF_SIZE, format, args);
va_end(args);

/* calculate log length */
if ((fmt_result > -1) && (fmt_result <= ULOG_LINE_BUF_SIZE))
/* calculate log length
* rt_vsnprintf would add \0 to the end, push \0 to ulog.async_rb will discard the follow char
* if fmt_result = ULOG_LINE_BUF_SIZE, then the last char must be \0
*/
if ((fmt_result > -1) && (fmt_result < ULOG_LINE_BUF_SIZE))
{
log_len = fmt_result;
}
Expand Down

0 comments on commit 05e5ec6

Please sign in to comment.