From 5961b0b5d776c0ae7a227bbe73831b0beee4d77a Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Mon, 4 May 2020 15:59:22 -0400 Subject: [PATCH] Fix: tests: `-Wstringop-overflow` warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I get the following warning when compiling with `-Wall -Werror` with gcc 9.3.0: In file included from ../../src/common/macros.h:15, from ../../src/common/lttng-kernel.h:14, from ../../src/bin/lttng-sessiond/trace-kernel.h:14, from test_kernel_data.c:16: In function ‘lttng_strnlen’, inlined from ‘lttng_strncpy’ at ../../src/common/macros.h:120:6, inlined from ‘test_create_kernel_event’ at test_kernel_data.c:136:2: ../../src/common/compat/string.h:28:8: error: ‘memchr’ reading 256 bytes from a region of size 11 [-Werror=stringop-overflow=] 28 | end = memchr(str, 0, max); | ^~~~~~~~~~~~~~~~~~~ Fix this warning by using the RANDOM_STRING_LEN value as the max number of bytes to copy. Signed-off-by: Francis Deslauriers Change-Id: I61752ee17163c4d642aad21b296c0fc4fad5b7a6 (cherry picked from commit 1dd622b10db0821d77490c937caee80c65332f14) Signed-off-by: Jérémie Galarneau --- tests/unit/test_kernel_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_kernel_data.c b/tests/unit/test_kernel_data.c index 134cd39ed..322c2eb21 100644 --- a/tests/unit/test_kernel_data.c +++ b/tests/unit/test_kernel_data.c @@ -134,7 +134,7 @@ static void test_create_kernel_event(void) memset(&ev, 0, sizeof(ev)); ok(!lttng_strncpy(ev.name, get_random_string(), - LTTNG_KERNEL_SYM_NAME_LEN), + RANDOM_STRING_LEN), "Validate string length"); ev.type = LTTNG_EVENT_TRACEPOINT; ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; -- 2.34.1