From cd1261ae00f4de719ee093ea3394ab9a6bc3ec5e Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 8 Jul 2021 21:22:49 +0800 Subject: [PATCH] trace: fix compiler complain on two variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the nightly test, the compiler complains: trace.c: In function ‘_spdk_trace_record’: 00:07:12.523 trace.c:144:53: error: ‘argval’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 00:07:12.523 memcpy(&buffer->data[offset], (uint8_t *)argval + argoff, 00:07:12.523 ^ 00:07:12.523 trace.c:145:36: error: ‘arglen’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 00:07:12.523 spdk_min(curlen, arglen - argoff)); And this patch is provided to fix such issue. Fixes #issue 2034 Change-Id: I4c78d63bdc6a7d166990ae1d18a6abf183efdee1 Signed-off-by: Ziye Yang Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8709 Reviewed-by: Konrad Sztyber Reviewed-by: Karol Latecki Reviewed-by: Tomasz Zawadzki Reviewed-by: Paul Luse Reviewed-by: Chengqiang Meng Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot --- lib/trace/trace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/trace/trace.c b/lib/trace/trace.c index 5adc1910c5..150022700c 100644 --- a/lib/trace/trace.c +++ b/lib/trace/trace.c @@ -116,7 +116,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ break; default: assert(0 && "Invalid trace argument type"); - break; + return; } /* Copy argument's data. For some argument types (strings) user is allowed to pass a @@ -141,6 +141,7 @@ _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, uint32_ curlen = spdk_min(sizeof(buffer->data) - offset, argument->size - argoff); if (argoff < arglen) { + assert(argval != NULL); memcpy(&buffer->data[offset], (uint8_t *)argval + argoff, spdk_min(curlen, arglen - argoff)); }