From: Jérémie Galarneau Date: Thu, 5 Sep 2024 21:29:53 +0000 (+0000) Subject: Clean-up: fix string truncation warning X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=6132bde02d87b20832e158649e78089a7dd8f7fc;p=lttng-tools.git Clean-up: fix string truncation warning 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 --- 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) {