Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): prefer memcpy over strncpy in DirExpan...



details:   https://anonhg.NetBSD.org/src/rev/35733405e6a5
branches:  trunk
changeset: 936600:35733405e6a5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 31 16:59:34 2020 +0000

description:
make(1): prefer memcpy over strncpy in DirExpandCurly

strncpy has unnecessary overhead when the source memory is already
guaranteed to contain no '\0'.

diffstat:

 usr.bin/make/dir.c |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (46 lines):

diff -r 4106440dccd9 -r 35733405e6a5 usr.bin/make/dir.c
--- a/usr.bin/make/dir.c        Fri Jul 31 16:59:04 2020 +0000
+++ b/usr.bin/make/dir.c        Fri Jul 31 16:59:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dir.c,v 1.76 2020/07/03 08:13:23 rillig Exp $  */
+/*     $NetBSD: dir.c,v 1.77 2020/07/31 16:59:34 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: dir.c,v 1.76 2020/07/03 08:13:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.77 2020/07/31 16:59:34 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)dir.c      8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: dir.c,v 1.76 2020/07/03 08:13:23 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.77 2020/07/31 16:59:34 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -723,13 +723,16 @@
         * Allocate room for the combination and install the three pieces.
         */
        file = bmake_malloc(otherLen + cp - start + 1);
+       char *fileend = file;
        if (brace != word) {
-           strncpy(file, word, brace-word);
+           memcpy(file, word, brace - word);
+           fileend += brace - word;
        }
        if (cp != start) {
-           strncpy(&file[brace-word], start, cp-start);
+           memcpy(fileend, start, cp - start);
+           fileend += cp - start;
        }
-       strcpy(&file[(brace-word)+(cp-start)], end);
+       strcpy(fileend, end);
 
        /*
         * See if the result has any wildcards in it. If we find one, call



Home | Main Index | Thread Index | Old Index