vmstat(1): various nits

Continue my parade on introspection tools by fixing:
- failed to check for null after reallocf
- avoid the comma operator
- mark usage as dead
- correct size of len
This commit is contained in:
Eitan Adler 2018-06-13 08:52:04 +00:00
parent 372639f944
commit baab2cf821
2 changed files with 10 additions and 7 deletions

View File

@ -7,8 +7,6 @@ PROG= vmstat
MAN= vmstat.8 MAN= vmstat.8
LIBADD= devstat kvm memstat xo util LIBADD= devstat kvm memstat xo util
WARNS?= 6
HAS_TESTS= HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests SUBDIR.${MK_TESTS}+= tests

View File

@ -218,7 +218,8 @@ main(int argc, char *argv[])
{ {
char *bp, *buf, *memf, *nlistf; char *bp, *buf, *memf, *nlistf;
float f; float f;
int bufsize, c, len, reps, todo; int bufsize, c, reps, todo;
size_t len;
unsigned int interval; unsigned int interval;
char errbuf[_POSIX2_LINE_MAX]; char errbuf[_POSIX2_LINE_MAX];
@ -318,7 +319,8 @@ main(int argc, char *argv[])
retry_nlist: retry_nlist:
if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) { if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) {
if (c > 0) { if (c > 0) {
bufsize = 0, len = 0; bufsize = 0;
len = 0;
/* /*
* 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not * 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not
@ -436,8 +438,11 @@ getdrivedata(char **argv)
if (isdigit(**argv)) if (isdigit(**argv))
break; break;
num_devices_specified++; num_devices_specified++;
specified_devices = realloc(specified_devices, specified_devices = reallocf(specified_devices,
sizeof(char *) * num_devices_specified); sizeof(char *) * num_devices_specified);
if (specified_devices == NULL) {
xo_errx(1, "%s", "reallocf (specified_devices)");
}
specified_devices[num_devices_specified - 1] = *argv; specified_devices[num_devices_specified - 1] = *argv;
} }
dev_select = NULL; dev_select = NULL;
@ -1206,7 +1211,7 @@ cpustats(void)
total = 0; total = 0;
for (state = 0; state < CPUSTATES; ++state) for (state = 0; state < CPUSTATES; ++state)
total += cur.cp_time[state]; total += cur.cp_time[state];
if (total) if (total > 0)
lpct = 100.0 / total; lpct = 100.0 / total;
else else
lpct = 0.0; lpct = 0.0;
@ -1682,7 +1687,7 @@ kread(int nlx, void *addr, size_t size)
kreado(nlx, addr, size, 0); kreado(nlx, addr, size, 0);
} }
static void static void __dead2
usage(void) usage(void)
{ {
xo_error("%s%s", xo_error("%s%s",