From ccd4fd852094a02d64fb092c541832a05025fd1b Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 15 May 2015 19:37:43 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=88=A0=E9=99=A4=E3=80=91?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E7=9A=84=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E7=AC=A6'\0'=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- .../components/easylogger/port/elog_port.c | 4 ++-- easylogger/inc/elog.h | 2 +- easylogger/src/elog.c | 22 ++++++++----------- easylogger/src/elog_utils.c | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/demo/os/rt-thread/components/easylogger/port/elog_port.c b/demo/os/rt-thread/components/easylogger/port/elog_port.c index 762cd5c..c6d1afd 100644 --- a/demo/os/rt-thread/components/easylogger/port/elog_port.c +++ b/demo/os/rt-thread/components/easylogger/port/elog_port.c @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Function: Portable interface for each platform. + * Function: Portable interface for RT-Thread. * Created on: 2015-04-28 */ @@ -44,7 +44,7 @@ ElogErrCode elog_port_init(void) { */ void elog_port_output(const char *output, size_t size) { /* output to terminal */ - rt_kprintf("%s", output); + rt_kprintf("%.*s", size, output); //TODO output to flash } diff --git a/easylogger/inc/elog.h b/easylogger/inc/elog.h index e9bd0ce..9360081 100644 --- a/easylogger/inc/elog.h +++ b/easylogger/inc/elog.h @@ -47,7 +47,7 @@ /* output filter's keyword max length */ #define ELOG_FILTER_KW_MAX_LEN 16 /* EasyLogger software version number */ -#define ELOG_SW_VERSION "0.05.10" +#define ELOG_SW_VERSION "0.05.15" /* EasyLogger assert for developer. */ #define ELOG_ASSERT(EXPR) \ diff --git a/easylogger/src/elog.c b/easylogger/src/elog.c index 1f85598..88c2a75 100644 --- a/easylogger/src/elog.c +++ b/easylogger/src/elog.c @@ -240,8 +240,8 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f log_len += elog_strcpy(log_len, log_buf + log_len, tag); /* if the tag length is less than 50% ELOG_FILTER_TAG_MAX_LEN, then fill space */ if (tag_len <= ELOG_FILTER_TAG_MAX_LEN / 2) { - memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len); - log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce); + memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len); + log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce); } log_len += elog_strcpy(log_len, log_buf + log_len, " "); } @@ -303,8 +303,8 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f log_len += elog_strcpy(log_len, log_buf + log_len, ": "); } - /* package other log data to buffer. CRLF length is 2. */ - fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - 2, format, args); + /* package other log data to buffer. CRLF length is 2. '\0' must be add in the end. */ + fmt_result = vsnprintf(log_buf + log_len, ELOG_BUF_SIZE - log_len - 2 + 1, format, args); va_end(args); @@ -316,20 +316,16 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f return; } - /* package end sign( CRLF and '\0' ) */ - if ((fmt_result > -1) && (fmt_result + log_len + 2 < ELOG_BUF_SIZE)) { + /* package CRLF */ + if ((fmt_result > -1) && (fmt_result + log_len + 2 <= ELOG_BUF_SIZE)) { log_len += fmt_result; - /* add CRLF */ + /* add CRLF, cut the '\0' */ log_len += elog_strcpy(log_len, log_buf + log_len, "\r\n"); - /* add '\0' */ - log_buf[log_len++] = '\0'; } else { /* add CRLF */ - log_buf[ELOG_BUF_SIZE - 3] = '\r'; - log_buf[ELOG_BUF_SIZE - 2] = '\n'; - /* add log end sign */ - log_buf[ELOG_BUF_SIZE - 1] = '\0'; + log_buf[ELOG_BUF_SIZE - 2] = '\r'; + log_buf[ELOG_BUF_SIZE - 1] = '\n'; } /* output log */ diff --git a/easylogger/src/elog_utils.c b/easylogger/src/elog_utils.c index 8f01c8d..9458cc2 100644 --- a/easylogger/src/elog_utils.c +++ b/easylogger/src/elog_utils.c @@ -35,7 +35,7 @@ size_t elog_strcpy(size_t cur_len, char *dst, const char *src) { const char *src_old = src; while (*src != 0) { /* make sure destination has enough space */ - if (cur_len++ < ELOG_BUF_SIZE) { + if (cur_len++ <= ELOG_BUF_SIZE) { *dst++ = *src++; } else { break;