]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
lnstat_util: Simplify alloc_and_open() a bit
authorPhil Sutter <phil@nwl.cc>
Thu, 24 Aug 2017 09:51:48 +0000 (11:51 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 24 Aug 2017 21:53:14 +0000 (14:53 -0700)
Relying upon callers and using unsafe strcpy() is probably not the best
idea. Aside from that, using snprintf() allows to format the string for
lf->path in one go.

Signed-off-by: Phil Sutter <phil@nwl.cc>
misc/lnstat_util.c

index cc54598fe1bef3f6e7e022f149f05a5ced693521..ec19238c24b94807acda80645d0d6654efb908dc 100644 (file)
@@ -180,11 +180,8 @@ static struct lnstat_file *alloc_and_open(const char *path, const char *file)
        }
 
        /* initialize */
-       /* de->d_name is guaranteed to be <= NAME_MAX */
-       strcpy(lf->basename, file);
-       strcpy(lf->path, path);
-       strcat(lf->path, "/");
-       strcat(lf->path, lf->basename);
+       snprintf(lf->basename, sizeof(lf->basename), "%s", file);
+       snprintf(lf->path, sizeof(lf->path), "%s/%s", path, file);
 
        /* initialize to default */
        lf->interval.tv_sec = 1;