From bfe363931d42c68767ebb096f5958b3b1dfde3bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sat, 14 Sep 2019 16:43:38 -0400 Subject: [PATCH] lttng: clean-up: silence bogus string truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc 9.1.0 reports enable_events.c:827:2: warning: ‘strncpy’ output truncated copying 9 bytes from a string of length 11 [-Wstringop-truncation] 827 | strncpy(ret, preamble, length); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc seems confused and using "sizeof" the preamble seems to make it understand the code flow and not generate the warning anymore. Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/enable_events.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index b4e6320c5..f11436e16 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -805,7 +805,7 @@ char *print_exclusions(char **names) { int length = 0; int i; - const char *preamble = " excluding "; + const char preamble[] = " excluding "; char *ret; int count = names ? strutils_array_of_strings_len(names) : 0; @@ -818,9 +818,8 @@ char *print_exclusions(char **names) length += strlen(names[i]) + 4; } - /* add length of preamble + one for NUL - one for last (missing) comma */ - length += strlen(preamble); - ret = zmalloc(length + 1); + length += sizeof(preamble); + ret = zmalloc(length); if (!ret) { return NULL; } -- 2.34.1