Remove strlcpy usage
authorKienan Stewart <kstewart@efficios.com>
Thu, 1 Feb 2024 19:02:19 +0000 (14:02 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 2 Feb 2024 21:49:20 +0000 (16:49 -0500)
The replacement for `strlcpy`, `strscpy`, was introduced in Linux
4.3. As lttng-modules master aims to support Linux 4.4+ at this time,
the version check can safely be removed.

See upstream commit:

    commit 30035e45753b708e7d47a98398500ca005e02b86
    Author: Chris Metcalf <cmetcalf@ezchip.com>
    Date:   Wed Apr 29 12:52:04 2015 -0400

        string: provide strscpy()

        The strscpy() API is intended to be used instead of strlcpy(),
        and instead of most uses of strncpy().

        - Unlike strlcpy(), it doesn't read from memory beyond (src + size).

        - Unlike strlcpy() or strncpy(), the API provides an easy way to check
          for destination buffer overflow: an -E2BIG error return value.

        - The provided implementation is robust in the face of the source
          buffer being asynchronously changed during the copy, unlike the
          current implementation of strlcpy().

        - Unlike strncpy(), the destination buffer will be NUL-terminated
          if the string in the source buffer is too long.

        - Also unlike strncpy(), the destination buffer will not be updated
          beyond the NUL termination, avoiding strncpy's behavior of zeroing
          the entire tail end of the destination buffer.  (A memset() after
          the strscpy() can be used if this behavior is desired.)

        - The implementation should be reasonably performant on all
          platforms since it uses the asm/word-at-a-time.h API rather than
          simple byte copy.  Kernel-to-kernel string copy is not considered
          to be performance critical in any case.

Change-Id: I31fefde148d5b63a30532fbcb4b59bb951bba902
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/lib/ringbuffer/ring_buffer_backend.c

index c3067d039c69cd11176283608dfaa2795a502a11..02a9d4870f5289e5cc5576228759469111440498 100644 (file)
@@ -405,11 +405,7 @@ int channel_backend_init(struct channel_backend *chanb,
        chanb->extra_reader_sb =
                        (config->mode == RING_BUFFER_OVERWRITE) ? 1 : 0;
        chanb->num_subbuf = num_subbuf;
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,8,0))
        strscpy(chanb->name, name, NAME_MAX);
-#else
-       strlcpy(chanb->name, name, NAME_MAX);
-#endif
        memcpy(&chanb->config, config, sizeof(chanb->config));
 
        if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
This page took 0.026047 seconds and 4 git commands to generate.