Clean-up: fix string truncation warning
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 5 Sep 2024 21:29:53 +0000 (21:29 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 5 Sep 2024 21:29:53 +0000 (21:29 +0000)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/trace-ust.cpp

index a298d6f559eb966f9d6ad91c913a0b1b6cd83e7e..fe0f2f2dff21958e5b97f896875b4390a3a0d296 100644 (file)
@@ -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) {
This page took 0.0286 seconds and 4 git commands to generate.