diff options
-rw-r--r-- | usr.bin/top/display.c | 16 | ||||
-rw-r--r-- | usr.bin/top/machine.c | 18 | ||||
-rw-r--r-- | usr.bin/top/screen.c | 4 | ||||
-rw-r--r-- | usr.bin/top/screen.h | 3 | ||||
-rw-r--r-- | usr.bin/top/utils.c | 6 |
5 files changed, 22 insertions, 25 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c index 5943986e3756..bad52f5c2e06 100644 --- a/usr.bin/top/display.c +++ b/usr.bin/top/display.c @@ -148,8 +148,8 @@ display_resize(void) } /* now, allocate space for the screen buffer */ - screenbuf = malloc(lines * display_width); - if (screenbuf == (char *)NULL) + screenbuf = calloc(lines, display_width); + if (screenbuf == NULL) { /* oops! */ return(-1); @@ -205,23 +205,23 @@ int display_init(struct statics * statics) procstate_names = statics->procstate_names; num_procstates = string_count(procstate_names); assert(num_procstates > 0); - lprocstates = malloc(num_procstates * sizeof(int)); + lprocstates = calloc(num_procstates, sizeof(int)); cpustate_names = statics->cpustate_names; swap_names = statics->swap_names; num_swap = string_count(swap_names); assert(num_swap > 0); - lswap = malloc(num_swap * sizeof(int)); + lswap = calloc(num_swap, sizeof(int)); num_cpustates = string_count(cpustate_names); assert(num_cpustates > 0); - lcpustates = malloc(num_cpustates * sizeof(int) * statics->ncpus); - cpustate_columns = malloc(num_cpustates * sizeof(int)); + lcpustates = calloc(num_cpustates * sizeof(int), statics->ncpus); + cpustate_columns = calloc(num_cpustates, sizeof(int)); memory_names = statics->memory_names; num_memory = string_count(memory_names); assert(num_memory > 0); - lmemory = malloc(num_memory * sizeof(int)); + lmemory = calloc(num_memory, sizeof(int)); arc_names = statics->arc_names; carc_names = statics->carc_names; @@ -745,7 +745,7 @@ trim_header(char *text) width = display_width; header_length = strlen(text); if (header_length >= width) { - s = malloc((width + 1) * sizeof(char)); + s = calloc((width + 1), sizeof(char)); if (s == NULL) return (NULL); strncpy(s, text, width); diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 736e4201ac9e..c32aacef1446 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -382,9 +382,9 @@ machine_init(struct statics *statics) ncpus = 0; GETSYSCTL("kern.smp.maxcpus", maxcpu); size = sizeof(long) * maxcpu * CPUSTATES; - times = malloc(size); + times = calloc(size, 1); if (times == NULL) - err(1, "malloc %zu bytes", size); + err(1, "calloc %zu bytes", size); if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1) err(1, "sysctlbyname kern.cp_times"); pcpu_cp_time = calloc(1, size); @@ -779,11 +779,11 @@ get_process_info(struct system_info *si, struct process_select *sel, */ if (previous_proc_count_max < nproc) { free(previous_procs); - previous_procs = malloc(nproc * sizeof(*previous_procs)); + previous_procs = calloc(nproc, sizeof(*previous_procs)); free(previous_pref); - previous_pref = malloc(nproc * sizeof(*previous_pref)); + previous_pref = calloc(nproc, sizeof(*previous_pref)); if (previous_procs == NULL || previous_pref == NULL) { - (void) fprintf(stderr, "top: Out of memory.\n"); + fprintf(stderr, "top: Out of memory.\n"); quit(TOP_EX_SYS_ERROR); } previous_proc_count_max = nproc; @@ -996,9 +996,9 @@ format_next_process(caddr_t xhandle, char *(*get_userid)(uid_t), int flags) break; } - cmdbuf = malloc(cmdlen + 1); + cmdbuf = calloc(cmdlen + 1, 1); if (cmdbuf == NULL) { - warn("malloc(%d)", cmdlen + 1); + warn("calloc(%d)", cmdlen + 1); return NULL; } @@ -1031,9 +1031,9 @@ format_next_process(caddr_t xhandle, char *(*get_userid)(uid_t), int flags) size_t len; argbuflen = cmdlen * 4; - argbuf = malloc(argbuflen + 1); + argbuf = calloc(argbuflen + 1, 1); if (argbuf == NULL) { - warn("malloc(%zu)", argbuflen + 1); + warn("calloc(%zu)", argbuflen + 1); free(cmdbuf); return NULL; } diff --git a/usr.bin/top/screen.c b/usr.bin/top/screen.c index 6b9bbb4f169f..f1258040ce8a 100644 --- a/usr.bin/top/screen.c +++ b/usr.bin/top/screen.c @@ -3,7 +3,7 @@ * Version 3 * * This program may be freely redistributed, - * but this entire comment MUST remain intact. + * but this entire ceomment MUST remain intact. * * Copyright (c) 1984, 1989, William LeFebvre, Rice University * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University @@ -270,7 +270,7 @@ get_screensize(void) } void -top_standout(char *msg) +top_standout(const char *msg) { if (smart_terminal) { diff --git a/usr.bin/top/screen.h b/usr.bin/top/screen.h index 58ae1eb9aad3..f7ba38161a95 100644 --- a/usr.bin/top/screen.h +++ b/usr.bin/top/screen.h @@ -25,9 +25,8 @@ extern char *clear_to_end; extern int screen_length; extern int screen_width; -/* a function that puts a single character on stdout */ int clear_eol(int len); -void top_standout(char *msg); +void top_standout(const char *msg); void top_clear(void); void go_home(void); void reinit_screen(void); diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c index f9cf340444e4..365ef9f99bc6 100644 --- a/usr.bin/top/utils.c +++ b/usr.bin/top/utils.c @@ -26,8 +26,6 @@ #include <paths.h> #include <kvm.h> -void quit(int); - int atoiwi(const char *str) { @@ -201,10 +199,10 @@ argparse(char *line, int *cntp) cnt += 3; /* allocate a char * array to hold the pointers */ - argarray = malloc(cnt * sizeof(char *)); + argarray = calloc(cnt, sizeof(char *)); /* allocate another array to hold the strings themselves */ - args = malloc(length+2); + args = calloc(length+2, 1); /* initialization for main loop */ from = line; |