]> granicus.if.org Git - sysstat/commitdiff
Cosmetic fixes
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 3 May 2020 06:55:12 +0000 (08:55 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 3 May 2020 06:55:12 +0000 (08:55 +0200)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
16 files changed:
cifsiostat.c
common.c
count.c
ioconf.c
iostat.c
mpstat.c
pidstat.c
pr_stats.c
raw_stats.c
rd_stats.c
sa_common.c
sa_conv.c
sadc.c
sadf.c
sar.c
svg_stats.c

index 2b5ff87c0ec827afc352a21011287810337b58e2..a5c77bce5af87c13079949866689eb75090d7100 100644 (file)
@@ -175,8 +175,8 @@ struct io_cifs *add_list_cifs(struct io_cifs **clist, char *name)
                }
                memset(c->cifs_stats[i], 0, CIFS_ST_SIZE);
        }
-       strncpy(c->name, name, MAX_NAME_LEN);
-       c->name[MAX_NAME_LEN - 1] = '\0';
+       strncpy(c->name, name, sizeof(c->name));
+       c->name[sizeof(c->name) - 1] = '\0';
        c->exist = TRUE;
        c->next = cs;
 
@@ -227,8 +227,8 @@ void read_cifs_stat(int curr)
                        else {
                                start = 1;
                        }
-                       strncpy(cifs_name, name_tmp, MAX_NAME_LEN);
-                       cifs_name[MAX_NAME_LEN - 1] = '\0';
+                       strncpy(cifs_name, name_tmp, sizeof(cifs_name));
+                       cifs_name[sizeof(cifs_name) - 1] = '\0';
                        memset(&scifs, 0, CIFS_ST_SIZE);
                }
                else {
index 7071ec6ed15d4a8ed25b9a79fe5520c8e87eee97..75794927064f264542c5d8e0431d646abd21ef36 100644 (file)
--- a/common.c
+++ b/common.c
@@ -393,8 +393,8 @@ int get_wwnid_from_pretty(char *pretty, unsigned long long *wwn, unsigned int *p
 
                if (!strncmp(name, pretty, FILENAME_MAX)) {
                        /* We have found pretty name for current persistent one */
-                       strncpy(wwn_name, drd->d_name, FILENAME_MAX);
-                       wwn_name[FILENAME_MAX - 1] = '\0';
+                       strncpy(wwn_name, drd->d_name, sizeof(wwn_name));
+                       wwn_name[sizeof(wwn_name) - 1] = '\0';
 
                        /* Try to extract WWN */
                        if (!extract_wwnid(wwn_name, wwn, part_nr)) {
@@ -723,8 +723,8 @@ char *device_name(char *name)
        if (!strncmp(resolved_name, "/dev/", 5)) {
                i = 5;
        }
-       strncpy(out, resolved_name + i, MAX_FILE_LEN);
-       out[MAX_FILE_LEN - 1] = '\0';
+       strncpy(out, resolved_name + i, sizeof(out));
+       out[sizeof(out) - 1] = '\0';
 
        /* Some devices may have a slash in their name (eg. cciss/c0d0...) */
        while ((slash = strchr(out, '/'))) {
@@ -873,7 +873,7 @@ char *get_persistent_name_path(char *name)
 {
        static char path[PATH_MAX];
 
-       snprintf(path, PATH_MAX, "%s/%s",
+       snprintf(path, sizeof(path), "%s/%s",
                 get_persistent_type_dir(persistent_name_type), name);
 
        if (access(path, F_OK)) {
@@ -992,8 +992,8 @@ char *get_persistent_name_from_pretty(char *pretty)
 
                if (!strncmp(name, pretty, FILENAME_MAX)) {
                        /* We have found pretty name for current persistent one */
-                       strncpy(persist_name, persist_names[i], FILENAME_MAX);
-                       persist_name[FILENAME_MAX - 1] = '\0';
+                       strncpy(persist_name, persist_names[i], sizeof(persist_name));
+                       persist_name[sizeof(persist_name) - 1] = '\0';
                        break;
                }
        }
diff --git a/count.c b/count.c
index 58e68ed2850e2f3e6c271684252494f5732dcf9c..c2afee742e2504e2f8aadd2738b19fdd0adb48a0 100644 (file)
--- a/count.c
+++ b/count.c
@@ -73,8 +73,8 @@ int get_sys_cpu_nr(int highest)
        while ((drd = readdir(dir)) != NULL) {
 
                if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) {
-                       snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, drd->d_name);
-                       line[MAX_PF_NAME - 1] = '\0';
+                       snprintf(line, sizeof(line), "%s/%s", SYSFS_DEVCPU, drd->d_name);
+                       line[sizeof(line) - 1] = '\0';
                        if (stat(line, &buf) < 0)
                                continue;
                        if (S_ISDIR(buf.st_mode)) {
index 5c73f58e545d3e70402f33140ae962917dc7d180..a9375c96d77ce2a72be19fdbad3e664075e80c85 100644 (file)
--- a/ioconf.c
+++ b/ioconf.c
@@ -154,17 +154,17 @@ int ioc_init(void)
        if ((fp = fopen(IOCONF, "r")) == NULL) {
                if ((fp = fopen(LOCAL_IOCONF, "r")) == NULL)
                        return 0;
-               strncpy(ioconf_name, LOCAL_IOCONF, 64);
+               strncpy(ioconf_name, LOCAL_IOCONF, sizeof(ioconf_name));
        }
        else {
-               strncpy(ioconf_name, IOCONF, 64);
+               strncpy(ioconf_name, IOCONF, sizeof(ioconf_name));
        }
-       ioconf_name[63] = '\0';
+       ioconf_name[sizeof(ioconf_name) - 1] = '\0';
 
        /* Init ioc_refnr array */
        memset(ioc_refnr, 0, sizeof(ioc_refnr));
 
-       while (fgets(buf, IOC_LINESIZ - 1, fp)) {
+       while (fgets(buf, sizeof(buf) - 1, fp)) {
 
                if ((*buf == '#') || (*buf == '\n'))
                        continue;
@@ -412,8 +412,8 @@ char *ioc_name(unsigned int major, unsigned int minor)
 
        /* Is this an extension record? */
        if (p->blkp->ext && (p->blkp->ext_minor == minor)) {
-               strncpy(name, p->blkp->ext_name, IOC_DEVLEN);
-               name[IOC_DEVLEN - 1] = '\0';
+               strncpy(name, p->blkp->ext_name, sizeof(name));
+               name[sizeof(name) - 1] = '\0';
                return (name);
        }
 
@@ -511,8 +511,8 @@ char *transform_devmapname(unsigned int major, unsigned int minor)
        while ((dp = readdir(dm_dir)) != NULL) {
                /* For each file in DEVMAP_DIR */
 
-               snprintf(filen, MAX_FILE_LEN, "%s/%s", DEVMAP_DIR, dp->d_name);
-               filen[MAX_FILE_LEN - 1] = '\0';
+               snprintf(filen, sizeof(filen), "%s/%s", DEVMAP_DIR, dp->d_name);
+               filen[sizeof(filen) - 1] = '\0';
 
                if (__stat(filen, &aux) == 0) {
                        /* Get its minor and major numbers */
@@ -521,8 +521,8 @@ char *transform_devmapname(unsigned int major, unsigned int minor)
                        dm_minor = minor(aux.st_rdev);
 
                        if ((dm_minor == minor) && (dm_major == major)) {
-                               strncpy(name, dp->d_name, MAX_NAME_LEN);
-                               name[MAX_NAME_LEN - 1] = '\0';
+                               strncpy(name, dp->d_name, sizeof(name));
+                               name[sizeof(name) - 1] = '\0';
                                dm_name = name;
                                break;
                        }
index 417197d964cce01ec84bd03e7d1ed146ff422df3..2b8a58aa0c4087ad7dea3b162f2144ba89ac5730 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -2143,8 +2143,8 @@ int main(int argc, char **argv)
                        if (argv[opt++][0] == '+') {
                                flags |= I_D_ALL_DIR;
                        }
-                       strncpy(alt_dir, argv[opt++], MAX_FILE_LEN);
-                       alt_dir[MAX_FILE_LEN - 1] = '\0';
+                       strncpy(alt_dir, argv[opt++], sizeof(alt_dir));
+                       alt_dir[sizeof(alt_dir) - 1] = '\0';
                        if (!check_dir(alt_dir)) {
                                usage(argv[0]);
                        }
@@ -2154,11 +2154,11 @@ int main(int argc, char **argv)
                        if (!argv[++opt]) {
                                usage(argv[0]);
                        }
-                       if (strnlen(argv[opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1) {
+                       if (strnlen(argv[opt], sizeof(persistent_name_type)) >= sizeof(persistent_name_type) - 1) {
                                usage(argv[0]);
                        }
-                       strncpy(persistent_name_type, argv[opt], MAX_FILE_LEN - 1);
-                       persistent_name_type[MAX_FILE_LEN - 1] = '\0';
+                       strncpy(persistent_name_type, argv[opt], sizeof(persistent_name_type) - 1);
+                       persistent_name_type[sizeof(persistent_name_type) - 1] = '\0';
                        strtolower(persistent_name_type);
                        /* Check that this is a valid type of persistent device name */
                        if (!get_persistent_type_dir(persistent_name_type)) {
index b0033011d25daf1b9b6718f4a630a5644f86f87f..3aca60fdf6e4e1875660060f460f0d423c82a92b 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -305,8 +305,8 @@ int get_node_placement(int nr_cpus, int cpu_per_node[], int cpu2node[])
        cpu_per_node[0] = nr_cpus;
 
        for (cpu = 0; cpu < nr_cpus; cpu++) {
-               snprintf(line, MAX_PF_NAME, "%s/cpu%d", SYSFS_DEVCPU, cpu);
-               line[MAX_PF_NAME - 1] = '\0';
+               snprintf(line, sizeof(line), "%s/cpu%d", SYSFS_DEVCPU, cpu);
+               line[sizeof(line) - 1] = '\0';
 
                /* Open relevant /sys directory */
                if ((dir = opendir(line)) == NULL)
@@ -371,8 +371,8 @@ void read_topology(int nr_cpus, struct cpu_topology *cpu_topo)
                cpu_topo_i = cpu_topo + cpu;
 
                /* Read current CPU's socket number */
-               snprintf(filename, MAX_PF_NAME, "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, PHYS_PACK_ID);
-               filename[MAX_PF_NAME - 1] = '\0';
+               snprintf(filename, sizeof(filename), "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, PHYS_PACK_ID);
+               filename[sizeof(filename) - 1] = '\0';
 
                if ((fp = fopen(filename, "r")) != NULL) {
                        rc = fscanf(fp, "%d", &cpu_topo_i->phys_package_id);
@@ -384,8 +384,8 @@ void read_topology(int nr_cpus, struct cpu_topology *cpu_topo)
                }
 
                /* Read current CPU's logical core id number */
-               snprintf(filename, MAX_PF_NAME, "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, THREAD_SBL_LST);
-               filename[MAX_PF_NAME - 1] = '\0';
+               snprintf(filename, sizeof(filename), "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, THREAD_SBL_LST);
+               filename[sizeof(filename) - 1] = '\0';
 
                if ((fp = fopen(filename, "r")) != NULL) {
                        rc = fscanf(fp, "%d", &cpu_topo_i->logical_core_id);
index 02f83bf22bdd5f8be3c49c04e6fa9c1bfe8108ef..10e5821e941eb6113edf6946f0612979367fbe60 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -664,7 +664,7 @@ int read_proc_pid_cmdline(pid_t pid, struct st_pid *plist, pid_t tgid)
 
        memset(line, 0, MAX_CMDLINE_LEN);
 
-       len = fread(line, 1, MAX_CMDLINE_LEN - 1, fp);
+       len = fread(line, 1, sizeof(line) - 1, fp);
        fclose(fp);
 
        if (len) {
@@ -676,8 +676,8 @@ int read_proc_pid_cmdline(pid_t pid, struct st_pid *plist, pid_t tgid)
                                line[i] = ' ';
                        }
                }
-               strncpy(plist->cmdline, line, MAX_CMDLINE_LEN - 1);
-               plist->cmdline[MAX_CMDLINE_LEN - 1] = '\0';
+               strncpy(plist->cmdline, line, sizeof(plist->cmdline) - 1);
+               plist->cmdline[sizeof(plist->cmdline) - 1] = '\0';
        }
        else {
                /* proc/.../cmdline was empty */
@@ -2312,8 +2312,8 @@ int write_stats(int curr, int dis)
                strcpy(cur_time[!curr], "# Time     ");
        }
        else if (PRINT_SEC_EPOCH(pidflag)) {
-               snprintf(cur_time[!curr], TIMESTAMP_LEN, "%-11ld", mktime(&ps_tstamp[!curr]));
-               cur_time[!curr][TIMESTAMP_LEN - 1] = '\0';
+               snprintf(cur_time[!curr], sizeof(cur_time[!curr]), "%-11ld", mktime(&ps_tstamp[!curr]));
+               cur_time[!curr][sizeof(cur_time[!curr]) - 1] = '\0';
        }
        else if (is_iso_time_fmt()) {
                strftime(cur_time[!curr], sizeof(cur_time[!curr]), "%H:%M:%S", &ps_tstamp[!curr]);
@@ -2324,8 +2324,8 @@ int write_stats(int curr, int dis)
 
        /* Get current timestamp */
        if (PRINT_SEC_EPOCH(pidflag)) {
-               snprintf(cur_time[curr], TIMESTAMP_LEN, "%-11ld", mktime(&ps_tstamp[curr]));
-               cur_time[curr][TIMESTAMP_LEN - 1] = '\0';
+               snprintf(cur_time[curr], sizeof(cur_time[curr]), "%-11ld", mktime(&ps_tstamp[curr]));
+               cur_time[curr][sizeof(cur_time[curr]) - 1] = '\0';
        }
        else if (is_iso_time_fmt()) {
                strftime(cur_time[curr], sizeof(cur_time[curr]), "%H:%M:%S", &ps_tstamp[curr]);
@@ -2584,8 +2584,8 @@ int main(int argc, char **argv)
                        if (!argv[++opt]) {
                                usage(argv[0]);
                        }
-                       strncpy(commstr, argv[opt++], MAX_COMM_LEN);
-                       commstr[MAX_COMM_LEN - 1] = '\0';
+                       strncpy(commstr, argv[opt++], sizeof(commstr));
+                       commstr[sizeof(commstr) - 1] = '\0';
                        pidflag |= P_F_COMMSTR;
                        if (!strlen(commstr)) {
                                usage(argv[0]);
@@ -2596,8 +2596,8 @@ int main(int argc, char **argv)
                        if (!argv[++opt]) {
                                usage(argv[0]);
                        }
-                       strncpy(procstr, argv[opt++], MAX_COMM_LEN);
-                       procstr[MAX_COMM_LEN - 1] = '\0';
+                       strncpy(procstr, argv[opt++], sizeof(procstr));
+                       procstr[sizeof(procstr) - 1] = '\0';
                        pidflag |= P_F_PROCSTR;
                        if (!strlen(procstr)) {
                                usage(argv[0]);
@@ -2647,8 +2647,8 @@ int main(int argc, char **argv)
                        pidflag |= P_D_USERNAME;
                        if (argv[++opt] && (argv[opt][0] != '-') &&
                            (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
-                               strncpy(userstr, argv[opt++], MAX_USER_LEN);
-                               userstr[MAX_USER_LEN - 1] = '\0';
+                               strncpy(userstr, argv[opt++], sizeof(userstr));
+                               userstr[sizeof(userstr) - 1] = '\0';
                                pidflag |= P_F_USERSTR;
                                if (!strlen(userstr)) {
                                        usage(argv[0]);
index c5b113793f916a2a519e872ff6803382b5ae9543..8adc5046c70a5f97f0bcf8194cb19bff38a8dc00 100644 (file)
@@ -63,8 +63,8 @@ void print_hdr_line(char *p_timestamp, struct activity *a, int pos, int iwidth,
        int i = -1, j;
        int p = pos;
 
-       strncpy(hline, a->hdr_line, HEADER_LINE_LEN - 1);
-       hline[HEADER_LINE_LEN - 1] = '\0';
+       strncpy(hline, a->hdr_line, sizeof(hline) - 1);
+       hline[sizeof(hline) - 1] = '\0';
        for (hl = strtok(hline, "|"); hl && (pos > 0); hl = strtok(NULL, "|"), pos--);
        if (!hl)
                /* Bad @pos arg given to function */
index 73c80ac92057de0e773e400091cfaae23ea69640..e98e52b952fce725d6e6f6c87ef95d17de8a8fcb 100644 (file)
@@ -53,8 +53,8 @@ char *pfield(char *hdr_line, int pos)
        int i, j = 0;
 
        if (hdr_line) {
-               strncpy(hline, hdr_line, HEADER_LINE_LEN - 1);
-               hline[HEADER_LINE_LEN - 1] = '\0';
+               strncpy(hline, hdr_line, sizeof(hline) - 1);
+               hline[sizeof(hline) - 1] = '\0';
                idx = 0;
 
                for (hl = strtok(hline, "|"); hl && (pos > 0); hl = strtok(NULL, "|"), pos--);
@@ -67,8 +67,8 @@ char *pfield(char *hdr_line, int pos)
                        j = strcspn(hl, "&");
                        *(hl + j) = ';';
                }
-               strncpy(field, hl, HEADER_LINE_LEN);
-               field[HEADER_LINE_LEN - 1] = '\0';
+               strncpy(field, hl, sizeof(field));
+               field[sizeof(field) - 1] = '\0';
        }
 
        /* Display current field */
index cec026280620e627f344cabcfd6930b5dd55bf8c..b7990c2228d52ae1e468cd11a7bdabdd62f5a54d 100644 (file)
@@ -1048,8 +1048,8 @@ __nr_t read_net_dev(struct stats_net_dev *st_net_dev, __nr_t nr_alloc)
                        }
 
                        st_net_dev_i = st_net_dev + dev_read++;
-                       strncpy(iface, line, MINIMUM(pos, MAX_IFACE_LEN - 1));
-                       iface[MINIMUM(pos, MAX_IFACE_LEN - 1)] = '\0';
+                       strncpy(iface, line, MINIMUM(pos, sizeof(iface) - 1));
+                       iface[MINIMUM(pos, sizeof(iface) - 1)] = '\0';
                        sscanf(iface, "%s", st_net_dev_i->interface); /* Skip heading spaces */
                        sscanf(line + pos + 1, "%llu %llu %*u %*u %*u %*u %llu %llu %llu %llu "
                               "%*u %*u %*u %*u %*u %llu",
@@ -1171,8 +1171,8 @@ __nr_t read_net_edev(struct stats_net_edev *st_net_edev, __nr_t nr_alloc)
                        }
 
                        st_net_edev_i = st_net_edev + dev_read++;
-                       strncpy(iface, line, MINIMUM(pos, MAX_IFACE_LEN - 1));
-                       iface[MINIMUM(pos, MAX_IFACE_LEN - 1)] = '\0';
+                       strncpy(iface, line, MINIMUM(pos, sizeof(iface) - 1));
+                       iface[MINIMUM(pos, sizeof(iface) - 1)] = '\0';
                        sscanf(iface, "%s", st_net_edev_i->interface); /* Skip heading spaces */
                        sscanf(line + pos + 1, "%*u %*u %llu %llu %llu %llu %*u %*u %*u %*u "
                               "%llu %llu %llu %llu %llu",
@@ -2589,10 +2589,10 @@ __nr_t read_filesystem(struct stats_filesystem *st_filesystem, __nr_t nr_alloc)
                        st_filesystem_i->f_bavail = (unsigned long long) buf.f_bavail * (unsigned long long) buf.f_frsize;
                        st_filesystem_i->f_files  = (unsigned long long) buf.f_files;
                        st_filesystem_i->f_ffree  = (unsigned long long) buf.f_ffree;
-                       strncpy(st_filesystem_i->fs_name, fs_name, MAX_FS_LEN);
-                       st_filesystem_i->fs_name[MAX_FS_LEN - 1] = '\0';
-                       strncpy(st_filesystem_i->mountp, mountp, MAX_FS_LEN);
-                       st_filesystem_i->mountp[MAX_FS_LEN - 1] = '\0';
+                       strncpy(st_filesystem_i->fs_name, fs_name, sizeof(st_filesystem_i->fs_name));
+                       st_filesystem_i->fs_name[sizeof(st_filesystem_i->fs_name) - 1] = '\0';
+                       strncpy(st_filesystem_i->mountp, mountp, sizeof(st_filesystem_i->mountp));
+                       st_filesystem_i->mountp[sizeof(st_filesystem_i->mountp) - 1] = '\0';
                }
        }
 
@@ -2686,8 +2686,8 @@ __nr_t read_fchost(struct stats_fchost *st_fc, __nr_t nr_alloc)
                        st_fc_i->f_txframes = tx_frames;
                        st_fc_i->f_rxwords  = rx_words;
                        st_fc_i->f_txwords  = tx_words;
-                       memcpy(st_fc_i->fchost_name, drd->d_name, MAX_FCH_LEN);
-                       st_fc_i->fchost_name[MAX_FCH_LEN - 1] = '\0';
+                       memcpy(st_fc_i->fchost_name, drd->d_name, sizeof(st_fc_i->fchost_name));
+                       st_fc_i->fchost_name[sizeof(st_fc_i->fchost_name) - 1] = '\0';
                }
        }
 
index 0c1d9e227b2fb6249c2d7a56ae79cee2b20039ca..283a16d2421e4bee9a230d36c5fe4b16c6012e39 100644 (file)
@@ -151,12 +151,12 @@ void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name)
        *sa_name = 0;
 
        /* Look for saYYYYMMDD */
-       snprintf(filename, MAX_FILE_LEN,
+       snprintf(filename, sizeof(filename),
                 "%s/sa%04d%02d%02d", sa_dir,
                 rectime->tm_year + 1900,
                 rectime->tm_mon + 1,
                 rectime->tm_mday);
-       filename[MAX_FILE_LEN - 1] = '\0';
+       filename[sizeof(filename) - 1] = '\0';
 
        if (stat(filename, &sb) < 0)
                /* Cannot find or access saYYYYMMDD, so use saDD */
@@ -165,10 +165,10 @@ void guess_sa_name(char *sa_dir, struct tm *rectime, int *sa_name)
        nsec = sb.st_mtim.tv_nsec;
 
        /* Look for saDD */
-       snprintf(filename, MAX_FILE_LEN,
+       snprintf(filename, sizeof(filename),
                 "%s/sa%02d", sa_dir,
                 rectime->tm_mday);
-       filename[MAX_FILE_LEN - 1] = '\0';
+       filename[sizeof(filename) - 1] = '\0';
 
        if (stat(filename, &sb) < 0) {
                /* Cannot find or access saDD, so use saYYYYMMDD */
@@ -212,12 +212,12 @@ int set_default_file(char *datafile, int d_off, int sa_name)
 
        /* Set directory where daily data files will be saved */
        if (datafile[0]) {
-               strncpy(sa_dir, datafile, MAX_FILE_LEN);
+               strncpy(sa_dir, datafile, sizeof(sa_dir));
        }
        else {
-               strncpy(sa_dir, SA_DIR, MAX_FILE_LEN);
+               strncpy(sa_dir, SA_DIR, sizeof(sa_dir));
        }
-       sa_dir[MAX_FILE_LEN - 1] = '\0';
+       sa_dir[sizeof(sa_dir) - 1] = '\0';
 
        get_time(&rectime, d_off);
        if (sa_name < 0) {
@@ -2319,11 +2319,11 @@ int parse_sar_opt(char *argv[], int *opt, struct activity *act[],
                                return 0;
                        }
 
-                       if (strnlen(argv[*opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1)
+                       if (strnlen(argv[*opt], sizeof(persistent_name_type)) >= sizeof(persistent_name_type) - 1)
                                return 1;
 
-                       strncpy(persistent_name_type, argv[*opt], MAX_FILE_LEN - 1);
-                       persistent_name_type[MAX_FILE_LEN - 1] = '\0';
+                       strncpy(persistent_name_type, argv[*opt], sizeof(persistent_name_type) - 1);
+                       persistent_name_type[sizeof(persistent_name_type) - 1] = '\0';
                        strtolower(persistent_name_type);
                        if (!get_persistent_type_dir(persistent_name_type)) {
                                fprintf(stderr, _("Invalid type of persistent device name\n"));
index a61679c5b368ec7a71d05756aa168857a0ccf786..eb037df4ba67bb0d18510ae799b727cfaed76ee1 100644 (file)
--- a/sa_conv.c
+++ b/sa_conv.c
@@ -196,14 +196,14 @@ void upgrade_file_header(void *buffer, struct file_header *file_hdr, int previou
                file_hdr->sa_day = f_hdr_2171->sa_day;
                file_hdr->sa_month = f_hdr_2171->sa_month;
                file_hdr->sa_sizeof_long = f_hdr_2171->sa_sizeof_long;
-               strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, UTSNAME_LEN);
-               file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
-               strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, UTSNAME_LEN);
-               file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
-               strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, UTSNAME_LEN);
-               file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
-               strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, UTSNAME_LEN);
-               file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
+               strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, sizeof(file_hdr->sa_sysname));
+               file_hdr->sa_sysname[sizeof(file_hdr->sa_sysname) - 1] = '\0';
+               strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, sizeof(file_hdr->sa_nodename));
+               file_hdr->sa_nodename[sizeof(file_hdr->sa_nodename) - 1] = '\0';
+               strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, sizeof(file_hdr->sa_release));
+               file_hdr->sa_release[sizeof(file_hdr->sa_release) - 1] = '\0';
+               strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, sizeof(file_hdr->sa_machine));
+               file_hdr->sa_machine[sizeof(file_hdr->sa_machine) - 1] = '\0';
        }
 
        else if (previous_format == FORMAT_MAGIC_2173) {
@@ -810,8 +810,8 @@ void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
                        sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
                        sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
                        sndc->speed = 0; /* New field */
-                       strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
-                       sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+                       strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+                       sndc->interface[sizeof(sndc->interface) - 1] = '\0';
                        sndc->duplex = '\0'; /* New field */
                }
        }
@@ -830,8 +830,8 @@ void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
                        sndc->tx_compressed = sndp->tx_compressed;
                        sndc->multicast = sndp->multicast;
                        sndc->speed = 0; /* New field */
-                       strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
-                       sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+                       strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+                       sndc->interface[sizeof(sndc->interface) - 1] = '\0';
                        sndc->duplex = '\0'; /* New field */
                }
        }
@@ -850,8 +850,8 @@ void upgrade_stats_net_dev(struct activity *act[], int p, unsigned int magic,
                        sndc->tx_compressed = sndp->tx_compressed;
                        sndc->multicast = sndp->multicast;
                        sndc->speed = sndp->speed;
-                       strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
-                       sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+                       strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+                       sndc->interface[sizeof(sndc->interface) - 1] = '\0';
                        sndc->duplex = sndp->duplex;
                }
        }
@@ -894,8 +894,8 @@ void upgrade_stats_net_edev(struct activity *act[], int p, unsigned int magic,
                        snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
                        snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
                        snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
-                       strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
-                       snedc->interface[MAX_IFACE_LEN - 1] = '\0';
+                       strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
+                       snedc->interface[sizeof(snedc->interface) - 1] = '\0';
                }
        }
        else {
@@ -914,8 +914,8 @@ void upgrade_stats_net_edev(struct activity *act[], int p, unsigned int magic,
                        snedc->tx_fifo_errors = snedp->tx_fifo_errors;
                        snedc->rx_frame_errors = snedp->rx_frame_errors;
                        snedc->tx_carrier_errors = snedp->tx_carrier_errors;
-                       strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
-                       snedc->interface[MAX_IFACE_LEN - 1] = '\0';
+                       strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
+                       snedc->interface[sizeof(snedc->interface) - 1] = '\0';
                }
        }
 }
@@ -1197,16 +1197,16 @@ void upgrade_stats_filesystem(struct activity *act[], int p, int st_size)
                sfc->f_bavail = sfp->f_bavail;
                sfc->f_files = sfp->f_files;
                sfc->f_ffree = sfp->f_ffree;
-               strncpy(sfc->fs_name, sfp->fs_name, MAX_FS_LEN);
-               sfc->fs_name[MAX_FS_LEN - 1] = '\0';
+               strncpy(sfc->fs_name, sfp->fs_name, sizeof(sfc->fs_name));
+               sfc->fs_name[sizeof(sfc->fs_name) - 1] = '\0';
 
                if (st_size <= STATS_FILESYSTEM_8A_1_SIZE) {
                        /* mountp didn't exist with older versions */
                        sfc->mountp[0] = '\0';
                }
                else {
-                       strncpy(sfc->mountp, sfp->mountp, MAX_FS_LEN);
-                       sfc->mountp[MAX_FS_LEN - 1] = '\0';
+                       strncpy(sfc->mountp, sfp->mountp, sizeof(sfc->mountp));
+                       sfc->mountp[sizeof(sfc->mountp) - 1] = '\0';
                }
        }
 }
@@ -1507,11 +1507,11 @@ int upgrade_comment_record(int fd, int stdfd)
        char file_comment[MAX_COMMENT_LEN];
 
        /* Read the COMMENT record */
-       sa_fread(fd, file_comment, MAX_COMMENT_LEN, HARD_SIZE, UEOF_STOP);
-       file_comment[MAX_COMMENT_LEN - 1] = '\0';
+       sa_fread(fd, file_comment, sizeof(file_comment), HARD_SIZE, UEOF_STOP);
+       file_comment[sizeof(file_comment) - 1] = '\0';
 
        /* Then write it. No changes at this time */
-       if (write_all(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
+       if (write_all(stdfd, file_comment, sizeof(file_comment)) != sizeof(file_comment)) {
                fprintf(stderr, "\nwrite: %s\n", strerror(errno));
                return -1;
        }
diff --git a/sadc.c b/sadc.c
index a020fbae80dea59330585ea3145cc33688e783a0..84168802ce514e93f52b7a3c8e10aa3e8f14104c 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -525,14 +525,14 @@ void setup_file_hdr(int fd)
 
        /* Get system name, release number, hostname and machine architecture */
        __uname(&header);
-       strncpy(file_hdr.sa_sysname, header.sysname, UTSNAME_LEN);
-       file_hdr.sa_sysname[UTSNAME_LEN - 1]  = '\0';
-       strncpy(file_hdr.sa_nodename, header.nodename, UTSNAME_LEN);
-       file_hdr.sa_nodename[UTSNAME_LEN - 1] = '\0';
-       strncpy(file_hdr.sa_release, header.release, UTSNAME_LEN);
-       file_hdr.sa_release[UTSNAME_LEN - 1]  = '\0';
-       strncpy(file_hdr.sa_machine, header.machine, UTSNAME_LEN);
-       file_hdr.sa_machine[UTSNAME_LEN - 1]  = '\0';
+       strncpy(file_hdr.sa_sysname, header.sysname, sizeof(file_hdr.sa_sysname));
+       file_hdr.sa_sysname[sizeof(file_hdr.sa_sysname) - 1]  = '\0';
+       strncpy(file_hdr.sa_nodename, header.nodename, sizeof(file_hdr.sa_nodename));
+       file_hdr.sa_nodename[sizeof(file_hdr.sa_nodename) - 1] = '\0';
+       strncpy(file_hdr.sa_release, header.release, sizeof(file_hdr.sa_release));
+       file_hdr.sa_release[sizeof(file_hdr.sa_release) - 1]  = '\0';
+       strncpy(file_hdr.sa_machine, header.machine, sizeof(file_hdr.sa_machine));
+       file_hdr.sa_machine[sizeof(file_hdr.sa_machine) - 1]  = '\0';
 
        /* Get timezone value and save it */
        tzset();
@@ -1166,8 +1166,8 @@ void rw_sa_stat_loop(long count, int stdfd, int ofd, char ofile[],
                /* Rotate activity file if necessary */
                if (WANT_SA_ROTAT(flags)) {
                        /* The user specified '-' as the filename to use */
-                       strncpy(new_ofile, sa_dir, MAX_FILE_LEN - 1);
-                       new_ofile[MAX_FILE_LEN - 1] = '\0';
+                       strncpy(new_ofile, sa_dir, sizeof(new_ofile) - 1);
+                       new_ofile[sizeof(new_ofile) - 1] = '\0';
                        set_default_file(new_ofile, 0, USE_SA_YYYYMMDD(flags));
 
                        if (strcmp(ofile, new_ofile)) {
@@ -1258,8 +1258,8 @@ int main(int argc, char **argv)
                        if (!argv[++opt]) {
                                usage(argv[0]);
                        }
-                       strncpy(comment, argv[opt], MAX_COMMENT_LEN);
-                       comment[MAX_COMMENT_LEN - 1] = '\0';
+                       strncpy(comment, argv[opt], sizeof(comment));
+                       comment[sizeof(comment) - 1] = '\0';
                        if (!strlen(comment)) {
                                usage(argv[0]);
                        }
@@ -1294,8 +1294,8 @@ int main(int argc, char **argv)
                        }
                        else {
                                /* Write data to file */
-                               strncpy(ofile, argv[opt], MAX_FILE_LEN);
-                               ofile[MAX_FILE_LEN - 1] = '\0';
+                               strncpy(ofile, argv[opt], sizeof(ofile));
+                               ofile[sizeof(ofile) - 1] = '\0';
                        }
                }
 
diff --git a/sadf.c b/sadf.c
index 22e8a163e35410438deabf2f3281850ab6d51ce7..dd0a25b146de6184dc200a0ad02cc8448dfa4e1a 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -348,8 +348,8 @@ void list_fields(unsigned int act_id)
                        }
                        else {
                                msk = 1;
-                               strncpy(hline, act[i]->hdr_line, HEADER_LINE_LEN - 1);
-                               hline[HEADER_LINE_LEN - 1] = '\0';
+                               strncpy(hline, act[i]->hdr_line, sizeof(hline) - 1);
+                               hline[sizeof(hline) - 1] = '\0';
                                for (hl = strtok(hline, "|"); hl; hl = strtok(NULL, "|"), msk <<= 1) {
                                        if ((hl != NULL) && ((act[i]->opt_flags & 0xff) & msk)) {
                                                if (strchr(hl, '&')) {
@@ -1623,8 +1623,8 @@ int main(int argc, char **argv)
                                }
                                else if (!strncmp(t, K_PCPARCHIVE, strlen(K_PCPARCHIVE))) {
                                        v = t + strlen(K_PCPARCHIVE);
-                                       strncpy(pcparchive, v, MAX_FILE_LEN);
-                                       pcparchive[MAX_FILE_LEN - 1] = '\0';
+                                       strncpy(pcparchive, v, sizeof(pcparchive));
+                                       pcparchive[sizeof(pcparchive) - 1] = '\0';
                                }
                                else if (!strncmp(t, K_HZ, strlen(K_HZ))) {
                                        v = t + strlen(K_HZ);
@@ -1804,8 +1804,8 @@ int main(int argc, char **argv)
                                usage(argv[0]);
                        }
                        /* Write data to file */
-                       strncpy(dfile, argv[opt++], MAX_FILE_LEN);
-                       dfile[MAX_FILE_LEN - 1] = '\0';
+                       strncpy(dfile, argv[opt++], sizeof(dfile));
+                       dfile[sizeof(dfile) - 1] = '\0';
                        /* Check if this is an alternate directory for sa files */
                        check_alt_sa_dir(dfile, 0, -1);
                }
diff --git a/sar.c b/sar.c
index 79063dedfbad69d4ef92e939d0b7d035ceeb6ef8..64bddb59e3d9f84ecbe56c617da6ae1655b3e22d 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -380,9 +380,9 @@ void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
        /* Interval value in 1/100th of a second */
        itv = get_interval(record_hdr[2].uptime_cs, record_hdr[curr].uptime_cs);
 
-       strncpy(timestamp[curr], _("Average:"), TIMESTAMP_LEN);
-       timestamp[curr][TIMESTAMP_LEN - 1] = '\0';
-       memcpy(timestamp[!curr], timestamp[curr], TIMESTAMP_LEN);
+       strncpy(timestamp[curr], _("Average:"), sizeof(timestamp[curr]));
+       timestamp[curr][sizeof(timestamp[curr]) - 1] = '\0';
+       memcpy(timestamp[!curr], timestamp[curr], sizeof(timestamp[!curr]));
 
        /* Test stdout */
        TEST_STDOUT(STDOUT_FILENO);
@@ -1378,8 +1378,8 @@ int main(int argc, char **argv)
                        /* Save stats to a file */
                        if ((argv[++opt]) && strncmp(argv[opt], "-", 1) &&
                            (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
-                               strncpy(to_file, argv[opt++], MAX_FILE_LEN);
-                               to_file[MAX_FILE_LEN - 1] = '\0';
+                               strncpy(to_file, argv[opt++], sizeof(to_file));
+                               to_file[sizeof(to_file) - 1] = '\0';
                        }
                        else {
                                strcpy(to_file, "-");
@@ -1394,8 +1394,8 @@ int main(int argc, char **argv)
                        /* Read stats from a file */
                        if ((argv[++opt]) && strncmp(argv[opt], "-", 1) &&
                            (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
-                               strncpy(from_file, argv[opt++], MAX_FILE_LEN);
-                               from_file[MAX_FILE_LEN - 1] = '\0';
+                               strncpy(from_file, argv[opt++], sizeof(from_file));
+                               from_file[sizeof(from_file) - 1] = '\0';
                                /* Check if this is an alternate directory for sa files */
                                check_alt_sa_dir(from_file, day_offset, -1);
                        }
index fcf34f80bfb859235a6c81fbc52d5c4ff7271946..b2e52977aa5d5b729615dd544dc1500156e3a887 100644 (file)
@@ -4233,7 +4233,7 @@ __print_funct_t svg_print_pwr_cpufreq_stats(struct activity *a, int curr, int ac
        static double *spmin, *spmax;
        static char **out;
        static int *outsize;
-       char item_name[8];
+       char item_name[16];
        int i;
 
        if (action & F_BEGIN) {
@@ -4336,7 +4336,7 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action
        static double *spmin, *spmax;
        static char **out;
        static int *outsize;
-       char item_name[MAX_SENSORS_DEV_LEN + 8];
+       char item_name[MAX_SENSORS_DEV_LEN + 16];
        int i;
 
        if (action & F_BEGIN) {
@@ -4370,8 +4370,8 @@ __print_funct_t svg_print_pwr_fan_stats(struct activity *a, int curr, int action
 
                        spc = (struct stats_pwr_fan *) ((char *) a->buf[curr] + i * a->msize);
 
-                       snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
-                       item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+                       snprintf(item_name, sizeof(item_name), "%d: %s", i + 1, spc->device);
+                       item_name[sizeof(item_name) - 1] = '\0';
 
                        if (draw_activity_graphs(a->g_nr, g_type,
                                                 title, g_title, item_name, group,
@@ -4415,7 +4415,7 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio
        static double *spmin, *spmax;
        static char **out;
        static int *outsize;
-       char item_name[MAX_SENSORS_DEV_LEN + 8];
+       char item_name[MAX_SENSORS_DEV_LEN + 16];
        int i;
        double tval;
 
@@ -4468,8 +4468,8 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio
 
                        spc = (struct stats_pwr_temp *) ((char *) a->buf[curr] + i * a->msize);
 
-                       snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
-                       item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+                       snprintf(item_name, sizeof(item_name), "%d: %s", i + 1, spc->device);
+                       item_name[sizeof(item_name) - 1] = '\0';
 
                        if (draw_activity_graphs(a->g_nr, g_type,
                                                 title, g_title, item_name, group,
@@ -4513,7 +4513,7 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action,
        static double *spmin, *spmax;
        static char **out;
        static int *outsize;
-       char item_name[MAX_SENSORS_DEV_LEN + 8];
+       char item_name[MAX_SENSORS_DEV_LEN + 16];
        int i;
        double tval;
 
@@ -4566,8 +4566,8 @@ __print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action,
 
                        spc = (struct stats_pwr_in *) ((char *) a->buf[curr]  + i * a->msize);
 
-                       snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
-                       item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+                       snprintf(item_name, sizeof(item_name), "%d: %s", i + 1, spc->device);
+                       item_name[sizeof(item_name) - 1] = '\0';
 
                        if (draw_activity_graphs(a->g_nr, g_type,
                                                 title, g_title, item_name, group,