summaryrefslogtreecommitdiff
path: root/usr.bin/top/machine.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-07-27 13:57:51 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-07-27 13:57:51 +0000
commit49d3915810dac786aff156930f77e11675c4c0b7 (patch)
tree7f1c1e133fe24ca15c3a10d14ebc5f8d30a21185 /usr.bin/top/machine.c
parent88e65771b61fe8c6e023c7c1bbf32fb2aa18cfa3 (diff)
replace a few more malloc(n*m) idioms with calloc(n,m) for safety;
inspired by zinovik@cs.karelia.ru
Diffstat (limited to 'usr.bin/top/machine.c')
-rw-r--r--usr.bin/top/machine.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 58059465974..3eaa05dcb00 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.61 2007/05/29 00:56:56 otto Exp $ */
+/* $OpenBSD: machine.c,v 1.62 2007/07/27 13:57:50 deraadt Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -162,12 +162,12 @@ machine_init(struct statics *statics)
mib[1] = HW_NCPU;
if (sysctl(mib, 2, &ncpu, &size, NULL, 0) == -1)
return (-1);
- cpu_states = malloc(ncpu * CPUSTATES * sizeof(int64_t));
+ cpu_states = calloc(ncpu, CPUSTATES * sizeof(int64_t));
if (cpu_states == NULL)
err(1, NULL);
- cp_time = malloc(ncpu * sizeof(int64_t *));
- cp_old = malloc(ncpu * sizeof(int64_t *));
- cp_diff = malloc(ncpu * sizeof(int64_t *));
+ cp_time = calloc(ncpu, sizeof(int64_t *));
+ cp_old = calloc(ncpu, sizeof(int64_t *));
+ cp_diff = calloc(ncpu, sizeof(int64_t *));
if (cp_time == NULL || cp_old == NULL || cp_diff == NULL)
err(1, NULL);
for (cpu = 0; cpu < ncpu; cpu++) {
@@ -709,7 +709,7 @@ swapmode(int *used, int *total)
if (nswap == 0)
return 0;
- swdev = malloc(nswap * sizeof(*swdev));
+ swdev = calloc(nswap, sizeof(*swdev));
if (swdev == NULL)
return 0;