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]
This commit is contained in:
parent
8a46c08a2a
commit
d0bb69dc07
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334549
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -29,7 +29,7 @@
|
||||
int
|
||||
atoiwi(const char *str)
|
||||
{
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
len = strlen(str);
|
||||
if (len != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user