From 6132bde02d87b20832e158649e78089a7dd8f7fc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 5 Sep 2024 21:29:53 +0000 Subject: [PATCH] Clean-up: fix string truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some version of g++ emits the following warning: 'char* strncpy(char*, const char*, size_t)' output may be truncated copying 255 bytes from a string of length 255 [-Wstringop-truncation] Using the internal strncpy wrapper, which checks for truncation, fixes the problem. Change-Id: I8ab0f2cca0247eee329b137f547d3dfed32c995f Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/trace-ust.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/trace-ust.cpp b/src/bin/lttng-sessiond/trace-ust.cpp index a298d6f55..fe0f2f2df 100644 --- a/src/bin/lttng-sessiond/trace-ust.cpp +++ b/src/bin/lttng-sessiond/trace-ust.cpp @@ -489,7 +489,11 @@ enum lttng_error_code trace_ust_create_event(struct lttng_event *ev, } /* Copy event name */ - strncpy(local_ust_event->attr.name, ev->name, LTTNG_UST_ABI_SYM_NAME_LEN); + if (lttng_strncpy(local_ust_event->attr.name, ev->name, LTTNG_UST_ABI_SYM_NAME_LEN)) { + ret = LTTNG_ERR_INVALID; + goto error; + } + local_ust_event->attr.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; switch (ev->loglevel_type) { -- 2.34.1