Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2018 08:52:04 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335036 - head/usr.bin/vmstat
Message-ID:  <201806130852.w5D8q4l0093532@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Jun 13 08:52:04 2018
New Revision: 335036
URL: https://svnweb.freebsd.org/changeset/base/335036

Log:
  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

Modified:
  head/usr.bin/vmstat/Makefile
  head/usr.bin/vmstat/vmstat.c

Modified: head/usr.bin/vmstat/Makefile
==============================================================================
--- head/usr.bin/vmstat/Makefile	Wed Jun 13 08:50:43 2018	(r335035)
+++ head/usr.bin/vmstat/Makefile	Wed Jun 13 08:52:04 2018	(r335036)
@@ -7,8 +7,6 @@ PROG=	vmstat
 MAN=	vmstat.8
 LIBADD=	devstat kvm memstat xo util
 
-WARNS?=	6
-
 HAS_TESTS=
 SUBDIR.${MK_TESTS}+= tests
 

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806130852.w5D8q4l0093532>