diff options
| author | latercomer <[email protected]> | 2024-04-19 12:15:08 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2024-04-19 22:27:33 -0400 |
| commit | 6bfe740f27f03f17e9f5e40eba95d1321b0d3ee2 (patch) | |
| tree | f417aa76c5d928152212aebccf96461244907f30 /components/utilities | |
| parent | d1bb01621beec12a03fbe1489419cabde5461919 (diff) | |
解决LOG_RAW异步输出多条文本的时候会被截断,原因是rt_vsnprintf会在字符串最后添加\0,ulog.c中的do_output()将\0也压入到ulog.async_rb,当LOG_RAW没有及时输出,那么rb中的字符串被\0截断了,导致没法正确输出LOG_RAW信息
Diffstat (limited to 'components/utilities')
| -rw-r--r-- | components/utilities/ulog/ulog.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c index cb0790b9de..a880b71d27 100644 --- a/components/utilities/ulog/ulog.c +++ b/components/utilities/ulog/ulog.c @@ -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); } @@ -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; } |
