From 6bfe740f27f03f17e9f5e40eba95d1321b0d3ee2 Mon Sep 17 00:00:00 2001 From: latercomer Date: Fri, 19 Apr 2024 12:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3LOG=5FRAW=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=A4=9A=E6=9D=A1=E6=96=87=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E4=BC=9A=E8=A2=AB=E6=88=AA=E6=96=AD=EF=BC=8C?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=E6=98=AFrt=5Fvsnprintf=E4=BC=9A=E5=9C=A8?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=9C=80=E5=90=8E=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?\0=EF=BC=8Culog.c=E4=B8=AD=E7=9A=84do=5Foutput()=E5=B0=86\0?= =?UTF-8?q?=E4=B9=9F=E5=8E=8B=E5=85=A5=E5=88=B0ulog.async=5Frb=EF=BC=8C?= =?UTF-8?q?=E5=BD=93LOG=5FRAW=E6=B2=A1=E6=9C=89=E5=8F=8A=E6=97=B6=E8=BE=93?= =?UTF-8?q?=E5=87=BA=EF=BC=8C=E9=82=A3=E4=B9=88rb=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=A2=AB\0=E6=88=AA=E6=96=AD?= =?UTF-8?q?=E4=BA=86=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=B2=A1=E6=B3=95=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=BE=93=E5=87=BALOG=5FRAW=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/utilities/ulog/ulog.c | 10 +++++++--- 1 file 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; }