]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
whereis: use xstrncpy()
authorKarel Zak <kzak@redhat.com>
Mon, 20 May 2019 10:59:02 +0000 (12:59 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 20 May 2019 10:59:02 +0000 (12:59 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/whereis.c

index 21f381321bc88e19065142228ddff92fd302ee5a..debd5da55f4904954635f2d623b5b7dcf7d0be40 100644 (file)
@@ -264,8 +264,7 @@ static void dirlist_add_subdir(struct wh_dirlist **ls, int type, const char *dir
        DIR *dirp;
        struct dirent *dp;
 
-       strncpy(buf, dir, PATH_MAX);
-       buf[PATH_MAX - 1] = '\0';
+       xstrncpy(buf, dir, PATH_MAX);
 
        d = strchr(buf, '*');
        if (!d)
@@ -452,8 +451,7 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want)
        /* canonicalize pattern -- remove path suffix etc. */
        p = strrchr(pattern, '/');
        p = p ? p + 1 : (char *) pattern;
-       strncpy(patbuf, p, PATH_MAX);
-       patbuf[PATH_MAX - 1] = '\0';
+       xstrncpy(patbuf, p, PATH_MAX);
 
        DBG(SEARCH, ul_debug("lookup dirs for '%s' (%s), want: %s %s %s",
                                patbuf, pattern,