From a2dbaf7e8324891d786295df74b5b800576fe02f Mon Sep 17 00:00:00 2001 From: Richael Zhuang Date: Wed, 8 Apr 2020 09:50:13 +0800 Subject: [PATCH] log: spdk_log_dump more characters than required When the size of input buffer is larger than 16 and not divisible by 16, the final line will keep part of the characters of the last line. For example, if I want to dump "spdk dump 16 more chars",the output is: 00000000 "hexadecimal" spdk dump 16 mor 00000010 "hexadecimal" e charsmp 16 mor But the correct should be: 00000000 "hexadecimal" spdk dump 16 mor 00000010 "hexadecimal" e chars Signed-off-by: Richael Zhuang Change-Id: Iaf3f33c5ce68920ada83c59277f89a547e8030d7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1739 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/log/log.c | 1 + test/unit/lib/log/log.c/log_ut.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/log/log.c b/lib/log/log.c index a6b0a3764..79b7b8960 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -177,6 +177,7 @@ fdump(FILE *fp, const char *label, const uint8_t *buf, size_t len) if (idx != 0 && idx % 16 == 0) { snprintf(tmpbuf + total, sizeof tmpbuf - total, " %s", buf16); + memset(buf16, 0, sizeof buf16); fprintf(fp, "%s\n", tmpbuf); total = 0; } diff --git a/test/unit/lib/log/log.c/log_ut.c b/test/unit/lib/log/log.c/log_ut.c index 8c317e402..87a578b84 100644 --- a/test/unit/lib/log/log.c/log_ut.c +++ b/test/unit/lib/log/log.c/log_ut.c @@ -80,6 +80,8 @@ log_test(void) SPDK_DEBUGLOG(SPDK_LOG_LOG, "log test\n"); SPDK_LOGDUMP(SPDK_LOG_LOG, "log dump test:", "log dump", 8); spdk_log_dump(stderr, "spdk dump test:", "spdk dump", 9); + /* Test spdk_log_dump with more than 16 chars and less than 32 chars */ + spdk_log_dump(stderr, "spdk dump test:", "spdk dump 16 more chars", 23); spdk_log_close(); }