Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Jun 2018 02:58:53 +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: r334549 - head/usr.bin/top
Message-ID:  <201806030258.w532wrss070240@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Sun Jun  3 02:58:53 2018
New Revision: 334549
URL: https://svnweb.freebsd.org/changeset/base/334549

Log:
  top(1): misc minor improvements
  
  - use bool instead of int [0]
  - use calloc correctly [0]
  	(this also caught an incorrect sizeof argument) [1]
  - use size_t over int [2]
  - correct style
  
  Reported by:	pfg [0], scan-build [1], gcc [2]

Modified:
  head/usr.bin/top/commands.c
  head/usr.bin/top/machine.c
  head/usr.bin/top/utils.c

Modified: head/usr.bin/top/commands.c
==============================================================================
--- head/usr.bin/top/commands.c	Sun Jun  3 00:42:36 2018	(r334548)
+++ head/usr.bin/top/commands.c	Sun Jun  3 02:58:53 2018	(r334549)
@@ -43,7 +43,7 @@ struct errs		/* structure for a system-call error */
 
 static char *err_string(void);
 static int str_adderr(char *str, int len, int err);
-static int str_addarg(char *str, int len, char *arg, int first);
+static int str_addarg(char *str, int len, char *arg, bool first);
 
 /*
  *  show_help() - display the help screen; invoked in response to
@@ -199,9 +199,9 @@ static char err_listem[] = 
 char *err_string(void)
 {
     struct errs *errp;
-    int  cnt = 0;
-    int  first = true;
-    int  currerr = -1;
+    int cnt = 0;
+    bool first = true;
+    int currerr = -1;
     int stringlen;		/* characters still available in "string" */
     static char string[STRMAX];
 
@@ -279,7 +279,7 @@ str_adderr(char *str, int len, int err)
  */
 
 static int
-str_addarg(char str[], int len, char arg[], int first)
+str_addarg(char str[], int len, char arg[], bool first)
 {
     int arglen;
 

Modified: head/usr.bin/top/machine.c
==============================================================================
--- head/usr.bin/top/machine.c	Sun Jun  3 00:42:36 2018	(r334548)
+++ head/usr.bin/top/machine.c	Sun Jun  3 02:58:53 2018	(r334549)
@@ -381,8 +381,7 @@ machine_init(struct statics *statics)
 	cpumask = 0;
 	ncpus = 0;
 	GETSYSCTL("kern.smp.maxcpus", maxcpu);
-	size = sizeof(long) * maxcpu * CPUSTATES;
-	times = calloc(size, 1);
+	times = calloc(maxcpu * CPUSTATES, sizeof(long));
 	if (times == NULL)
 		err(1, "calloc %zu bytes", size);
 	if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1)
@@ -400,11 +399,10 @@ machine_init(struct statics *statics)
 			ncpus++;
 		}
 	}
-	size = sizeof(long) * ncpus * CPUSTATES;
-	assert(size > 0);
-	pcpu_cp_old = calloc(1, size);
-	pcpu_cp_diff = calloc(1, size);
-	pcpu_cpu_states = calloc(1, size);
+	assert(ncpus > 0);
+	pcpu_cp_old = calloc(ncpus * CPUSTATES, sizeof(long));
+	pcpu_cp_diff = calloc(ncpus * CPUSTATES, sizeof(long));
+	pcpu_cpu_states = calloc(ncpus * CPUSTATES, sizeof(int));
 	statics->ncpus = ncpus;
 
 	update_layout();

Modified: head/usr.bin/top/utils.c
==============================================================================
--- head/usr.bin/top/utils.c	Sun Jun  3 00:42:36 2018	(r334548)
+++ head/usr.bin/top/utils.c	Sun Jun  3 02:58:53 2018	(r334549)
@@ -29,7 +29,7 @@
 int
 atoiwi(const char *str)
 {
-    int len;
+    size_t len;
 
     len = strlen(str);
     if (len != 0)



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