Source-Changes-HG archive

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

[src/trunk]: src/usr.bin use memcpy() for strings that are not C strings.



details:   https://anonhg.NetBSD.org/src/rev/1076e11283a4
branches:  trunk
changeset: 460063:1076e11283a4
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Oct 05 23:35:57 2019 +0000

description:
use memcpy() for strings that are not C strings.
destinations are already sufficiently sized and nul terminated.

diffstat:

 usr.bin/make/arch.c     |   8 ++++----
 usr.bin/who/utmpentry.c |  20 ++++++++++----------
 2 files changed, 14 insertions(+), 14 deletions(-)

diffs (91 lines):

diff -r 977045eaff23 -r 1076e11283a4 usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Sat Oct 05 23:34:14 2019 +0000
+++ b/usr.bin/make/arch.c       Sat Oct 05 23:35:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $      */
+/*     $NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)arch.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: arch.c,v 1.70 2017/04/16 20:49:09 riastradh Exp $");
+__RCSID("$NetBSD: arch.c,v 1.71 2019/10/05 23:35:57 mrg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -635,7 +635,7 @@
            arh.ar_size[sizeof(arh.ar_size)-1] = '\0';
            size = (int)strtol(arh.ar_size, NULL, 10);
 
-           (void)strncpy(memName, arh.ar_name, sizeof(arh.ar_name));
+           memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
            for (cp = &memName[AR_MAX_NAME_LEN]; *cp == ' '; cp--) {
                continue;
            }
diff -r 977045eaff23 -r 1076e11283a4 usr.bin/who/utmpentry.c
--- a/usr.bin/who/utmpentry.c   Sat Oct 05 23:34:14 2019 +0000
+++ b/usr.bin/who/utmpentry.c   Sat Oct 05 23:35:57 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $       */
+/*     $NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $       */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: utmpentry.c,v 1.20 2019/10/04 11:43:07 mrg Exp $");
+__RCSID("$NetBSD: utmpentry.c,v 1.21 2019/10/05 23:35:57 mrg Exp $");
 #endif
 
 #include <sys/stat.h>
@@ -278,14 +278,14 @@
        /*
         * e has just been calloc'd. We don't need to clear it or
         * append null-terminators, because its length is strictly
-        * greater than the source string. Use strncpy to _read_
+        * greater than the source string. Use memcpy to _read_
         * up->ut_* because they may not be terminated. For this
         * reason we use the size of the _source_ as the length
         * argument.
         */
-       (void)strncpy(e->name, up->ut_name, sizeof(up->ut_name));
-       (void)strncpy(e->line, up->ut_line, sizeof(up->ut_line));
-       (void)strncpy(e->host, up->ut_host, sizeof(up->ut_host));
+       memcpy(e->name, up->ut_name, sizeof(up->ut_name));
+       memcpy(e->line, up->ut_line, sizeof(up->ut_line));
+       memcpy(e->host, up->ut_host, sizeof(up->ut_host));
 
        e->tv.tv_sec = up->ut_time;
        e->tv.tv_usec = 0;
@@ -309,14 +309,14 @@
        /*
         * e has just been calloc'd. We don't need to clear it or
         * append null-terminators, because its length is strictly
-        * greater than the source string. Use strncpy to _read_
+        * greater than the source string. Use memcpy to _read_
         * up->ut_* because they may not be terminated. For this
         * reason we use the size of the _source_ as the length
         * argument.
         */
-       (void)strncpy(e->name, up->ut_name, sizeof(up->ut_name));
-       (void)strncpy(e->line, up->ut_line, sizeof(up->ut_line));
-       (void)strncpy(e->host, up->ut_host, sizeof(up->ut_host));
+       memcpy(e->name, up->ut_name, sizeof(up->ut_name));
+       memcpy(e->line, up->ut_line, sizeof(up->ut_line));
+       memcpy(e->host, up->ut_host, sizeof(up->ut_host));
 
        e->tv = up->ut_tv;
        e->pid = up->ut_pid;



Home | Main Index | Thread Index | Old Index