Module Name: src Committed By: rillig Date: Fri Jul 31 16:59:35 UTC 2020
Modified Files: src/usr.bin/make: dir.c Log Message: make(1): prefer memcpy over strncpy in DirExpandCurly strncpy has unnecessary overhead when the source memory is already guaranteed to contain no '\0'. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/usr.bin/make/dir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/dir.c diff -u src/usr.bin/make/dir.c:1.76 src/usr.bin/make/dir.c:1.77 --- src/usr.bin/make/dir.c:1.76 Fri Jul 3 08:13:23 2020 +++ src/usr.bin/make/dir.c Fri Jul 31 16:59:34 2020 @@ -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 @@ DirExpandCurly(const char *word, const c * 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