Source-Changes-HG archive

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

[xsrc/trunk]: xsrc/external/mit/xedit/dist/lisp Switch strncpy(3) with length...



details:   https://anonhg.NetBSD.org/xsrc/rev/af4a1a6abd1e
branches:  trunk
changeset: 10406:af4a1a6abd1e
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Oct 23 00:06:07 2019 +0000

description:
Switch strncpy(3) with length of source to strlcpy(3) in xedit

Fixes build with gcc8.

diffstat:

 external/mit/xedit/dist/lisp/pathname.c |  15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diffs (36 lines):

diff -r ad18ab80f43a -r af4a1a6abd1e external/mit/xedit/dist/lisp/pathname.c
--- a/external/mit/xedit/dist/lisp/pathname.c   Wed Sep 25 14:53:20 2019 +0000
+++ b/external/mit/xedit/dist/lisp/pathname.c   Wed Oct 23 00:06:07 2019 +0000
@@ -1056,8 +1056,8 @@
  */
 {
     GC_ENTER();
-    int length;
     char *home = getenv("HOME"), data[PATH_MAX + 1];
+    char sepstr[] = {PATH_SEP, '\0'};
     LispObj *result;
 
     LispObj *host;
@@ -1067,16 +1067,15 @@
     if (host != UNSPEC && !STRINGP(host))
        LispDestroy("%s: bad hostname %s", STRFUN(builtin), STROBJ(host));
 
-    length = 0;
     if (home) {
-       length = strlen(home);
-       strncpy(data, home, length);
-       if (length && home[length - 1] != PATH_SEP)
-           data[length++] = PATH_SEP;
+       strlcpy(data, home, sizeof(data));
+       if (data[0] != '\0' && data[strlen(data) - 1] != PATH_SEP)
+               strlcat(data, sepstr, sizeof(data));
+    } else {
+       data[0] = '\0';
     }
-    data[length] = '\0';
 
-    result = LSTRING(data, length);
+    result = STRING(data);
     GC_PROTECT(result);
     result = APPLY1(Oparse_namestring, result);
     GC_LEAVE();



Home | Main Index | Thread Index | Old Index