fix: strncpy equals destination size warning
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 5 Oct 2020 19:31:42 +0000 (15:31 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 9 Oct 2020 20:31:09 +0000 (16:31 -0400)
Some versions of GCC when called with -Wstringop-truncation will warn
when doing a copy of the same size as the destination buffer with
strncpy :

  ‘strncpy’ specified bound 256 equals destination size [-Werror=stringop-truncation]

Since we unconditionally write '\0' in the last byte, reduce the copy
size by one.

Change-Id: Idb907c9550817a06fc0dffc489740f63d440e7d4
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
lttng-syscalls.c

index 49c0d81b9f2b75549ec326740d944760b13451af..b43dd570a029d1d5b1a4f6160765ae31668a6003 100644 (file)
@@ -719,7 +719,7 @@ int fill_table(const struct trace_syscall_entry *table, size_t table_len,
                        ev.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
                        break;
                }
-               strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
+               strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN - 1);
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_SYSCALL;
                chan_table[i] = _lttng_event_create(chan, &ev, filter,
This page took 0.027482 seconds and 4 git commands to generate.