]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/lnstat_util.c
Merge branch 'iproute2-master' into iproute2-next
[mirror_iproute2.git] / misc / lnstat_util.c
index d918151282f5510f0ce45a14ff29a96fec8cbe77..c2dc42ec1ff12a4848691d2e1ea2b642f0aa9631 100644 (file)
@@ -150,7 +150,8 @@ static int lnstat_scan_compat_rtstat_fields(struct lnstat_file *lf)
 {
        char buf[FGETS_BUF_SIZE];
 
-       strncpy(buf, RTSTAT_COMPAT_LINE, sizeof(buf)-1);
+       strncpy(buf, RTSTAT_COMPAT_LINE, sizeof(buf) - 1);
+       buf[sizeof(buf) - 1] = '\0';
 
        return __lnstat_scan_fields(lf, buf);
 }
@@ -173,20 +174,15 @@ static struct lnstat_file *alloc_and_open(const char *path, const char *file)
        struct lnstat_file *lf;
 
        /* allocate */
-       lf = malloc(sizeof(*lf));
+       lf = calloc(1, sizeof(*lf));
        if (!lf) {
                fprintf(stderr, "out of memory\n");
                return NULL;
        }
 
        /* initialize */
-       memset(lf, 0, sizeof(*lf));
-
-       /* 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;