]> Sergey Matveev's repositories - nnn.git/commitdiff
xstrdup: use memcpy
authorNRK <nrk@disroot.org>
Mon, 8 Aug 2022 21:01:30 +0000 (03:01 +0600)
committerNRK <nrk@disroot.org>
Tue, 16 Aug 2022 13:31:18 +0000 (19:31 +0600)
the length is already known, so memcpy should be faster than xstrsncpy.

src/nnn.c

index be6644f9cc068b60f9d76f440b723a90b6671807..924970db4c89ce9ca41af1a52b8690e0529097c2 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -985,10 +985,7 @@ static char *xstrdup(const char *restrict s)
 {
        size_t len = xstrlen(s) + 1;
        char *ptr = malloc(len);
-
-       if (ptr)
-               xstrsncpy(ptr, s, len);
-       return ptr;
+       return ptr ? memcpy(ptr, s, len) : NULL;
 }
 
 static bool is_suffix(const char *restrict str, const char *restrict suffix)