Skip to content

Commit

Permalink
Cosmetic fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastien GODARD <[email protected]>
  • Loading branch information
sysstat committed May 3, 2020
1 parent 9b091ea commit 3cb2a0f
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 135 deletions.
8 changes: 4 additions & 4 deletions cifsiostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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, '/'))) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions count.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
20 changes: 10 additions & 10 deletions ioconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions iostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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)) {
Expand Down
12 changes: 6 additions & 6 deletions mpstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions pidstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions pr_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions raw_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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--);
Expand All @@ -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 */
Expand Down
20 changes: 10 additions & 10 deletions rd_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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';
}
}

Expand Down Expand Up @@ -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';
}
}

Expand Down

0 comments on commit 3cb2a0f

Please sign in to comment.