Module Name: src Committed By: rillig Date: Sun Aug 2 08:06:35 UTC 2020
Modified Files: src/usr.bin/make: main.c Log Message: make(1): replace one instance of strncpy with snprintf GCC 9 incorrectly claims that the string might not be null-terminated. Since objdir is a global variable, it is initialized to zero, and the +1 in the size guarantees that this byte is always 0. Still, using strncpy to initialize a string is a waste of memory access, since it is enough if only the actual data is copied, without zeroing out all the remaining bytes. To generate a diff of this commit: cvs rdiff -u -r1.294 -r1.295 src/usr.bin/make/main.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/main.c diff -u src/usr.bin/make/main.c:1.294 src/usr.bin/make/main.c:1.295 --- src/usr.bin/make/main.c:1.294 Sat Aug 1 21:40:49 2020 +++ src/usr.bin/make/main.c Sun Aug 2 08:06:35 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.294 2020/08/01 21:40:49 rillig Exp $ */ +/* $NetBSD: main.c,v 1.295 2020/08/02 08:06:35 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.294 2020/08/01 21:40:49 rillig Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.295 2020/08/02 08:06:35 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.294 2020/08/01 21:40:49 rillig Exp $"); +__RCSID("$NetBSD: main.c,v 1.295 2020/08/02 08:06:35 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -745,7 +745,7 @@ Main_SetObjdir(const char *fmt, ...) (void)fprintf(stderr, "make warning: %s: %s.\n", path, strerror(errno)); } else { - strncpy(objdir, path, MAXPATHLEN); + snprintf(objdir, sizeof objdir, "%s", path); Var_Set(".OBJDIR", objdir, VAR_GLOBAL); setenv("PWD", objdir, 1); Dir_InitDot();