summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2006-04-02 21:38:58 +0000
committerDamien Miller <djm@cvs.openbsd.org>2006-04-02 21:38:58 +0000
commit5b14fea36497511e6428b2c588513d92bc92cb90 (patch)
tree0b66759932d131cfb42148e0672334d215e6b99f
parentba37f6b6fd488dbe7dd7be429e8b7a994a783155 (diff)
malloc(x * y) -> calloc(x, y) from adobriyan AT gmail.com, with tweaks
suggested by kjell@; ok otto@ pat@ millert@ jaredy@
-rw-r--r--lib/libc/locale/rune.c5
-rw-r--r--lib/libpcap/optimize.c9
-rw-r--r--lib/libpthread/uthread/uthread_spec.c8
-rw-r--r--libexec/ftpd/popen.c7
-rw-r--r--sbin/fsck_msdos/fat.c8
-rw-r--r--sbin/raidctl/raidctl.c7
-rw-r--r--sbin/sysctl/sysctl.c13
-rw-r--r--usr.bin/apropos/apropos.c7
-rw-r--r--usr.bin/elf2aout/elf2aout.c5
-rw-r--r--usr.bin/whatis/whatis.c5
-rw-r--r--usr.sbin/afs/src/arlad/messages.c4
-rw-r--r--usr.sbin/afs/src/arlad/volcache.c5
-rw-r--r--usr.sbin/afs/src/lib/ko/agetarg.c3
-rw-r--r--usr.sbin/afs/src/milko/lib/ropa/ropa.c5
-rw-r--r--usr.sbin/bind/lib/lwres/getipnode.c3
-rw-r--r--usr.sbin/route6d/route6d.c10
16 files changed, 41 insertions, 63 deletions
diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c
index cb0805e08b8..1ccd0871a61 100644
--- a/lib/libc/locale/rune.c
+++ b/lib/libc/locale/rune.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rune.c,v 1.1 2005/08/07 10:16:23 espie Exp $ */
+/* $OpenBSD: rune.c,v 1.2 2006/04/02 21:38:57 djm Exp $ */
/* $NetBSD: rune.c,v 1.26 2004/05/09 11:26:33 kleink Exp $ */
/*-
@@ -124,12 +124,11 @@ readentry(_RuneRange *rr, FILE *fp)
}
l = re[i].re_max - re[i].re_min + 1;
- re[i].re_rune_types = malloc(l * sizeof(_RuneType));
+ re[i].re_rune_types = calloc(l, sizeof(_RuneType));
if (!re[i].re_rune_types) {
error = ENOMEM;
goto fail;
}
- memset(re[i].re_rune_types, 0, l * sizeof(_RuneType));
if (fread(re[i].re_rune_types, sizeof(_RuneType), l, fp) != l)
goto fail2;
diff --git a/lib/libpcap/optimize.c b/lib/libpcap/optimize.c
index 48fc0dc6e94..3c5fa1eb795 100644
--- a/lib/libpcap/optimize.c
+++ b/lib/libpcap/optimize.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: optimize.c,v 1.11 2005/11/19 01:51:11 aaron Exp $ */
+/* $OpenBSD: optimize.c,v 1.12 2006/04/02 21:38:57 djm Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@@ -1922,7 +1922,7 @@ convert_code_r(p)
/* generate offset[] for convenience */
if (slen) {
- offset = (struct slist **)calloc(slen, sizeof(struct slist *));
+ offset = calloc(slen, sizeof(struct slist *));
if (!offset) {
bpf_error("not enough core");
/*NOTREACHED*/
@@ -2069,11 +2069,10 @@ icode_to_fcode(root, lenp)
unMarkAll();
n = *lenp = count_stmts(root);
- fp = (struct bpf_insn *)malloc(sizeof(*fp) * n);
+ fp = calloc(n, sizeof(*fp));
if (fp == NULL)
- bpf_error("malloc");
+ bpf_error("calloc");
- memset((char *)fp, 0, sizeof(*fp) * n);
fstart = fp;
ftail = fp + n;
diff --git a/lib/libpthread/uthread/uthread_spec.c b/lib/libpthread/uthread/uthread_spec.c
index b1fdeb9dfa5..41f66a7e1ac 100644
--- a/lib/libpthread/uthread/uthread_spec.c
+++ b/lib/libpthread/uthread/uthread_spec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_spec.c,v 1.7 2001/08/21 19:24:53 fgsch Exp $ */
+/* $OpenBSD: uthread_spec.c,v 1.8 2006/04/02 21:38:57 djm Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -134,11 +134,7 @@ _thread_cleanupspecific(void)
static inline const void **
pthread_key_allocate_data(void)
{
- const void **new_data;
- if ((new_data = (const void **) malloc(sizeof(void *) * PTHREAD_KEYS_MAX)) != NULL) {
- memset((void *) new_data, 0, sizeof(void *) * PTHREAD_KEYS_MAX);
- }
- return (new_data);
+ return calloc(PTHREAD_KEYS_MAX, sizeof(void *));
}
int
diff --git a/libexec/ftpd/popen.c b/libexec/ftpd/popen.c
index 4b57d570a78..c47918d7f16 100644
--- a/libexec/ftpd/popen.c
+++ b/libexec/ftpd/popen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: popen.c,v 1.20 2003/12/10 22:57:12 deraadt Exp $ */
+/* $OpenBSD: popen.c,v 1.21 2006/04/02 21:38:56 djm Exp $ */
/* $NetBSD: popen.c,v 1.5 1995/04/11 02:45:00 cgd Exp $ */
/*
@@ -39,7 +39,7 @@
static const char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
#else
static const char rcsid[] =
- "$OpenBSD: popen.c,v 1.20 2003/12/10 22:57:12 deraadt Exp $";
+ "$OpenBSD: popen.c,v 1.21 2006/04/02 21:38:56 djm Exp $";
#endif
#endif /* not lint */
@@ -84,9 +84,8 @@ ftpd_popen(char *program, char *type)
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return (NULL);
- if ((pids = (pid_t *)malloc((u_int)(fds * sizeof(pid_t)))) == NULL)
+ if ((pids = calloc(fds, sizeof(pid_t))) == NULL)
return (NULL);
- memset(pids, 0, fds * sizeof(pid_t));
}
if (pipe(pdes) < 0)
return (NULL);
diff --git a/sbin/fsck_msdos/fat.c b/sbin/fsck_msdos/fat.c
index 637624b8f9a..b81c3188fbc 100644
--- a/sbin/fsck_msdos/fat.c
+++ b/sbin/fsck_msdos/fat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fat.c,v 1.13 2006/03/20 20:11:02 dhill Exp $ */
+/* $OpenBSD: fat.c,v 1.14 2006/04/02 21:38:56 djm Exp $ */
/* $NetBSD: fat.c,v 1.8 1997/10/17 11:19:53 ws Exp $ */
/*
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: fat.c,v 1.13 2006/03/20 20:11:02 dhill Exp $";
+static char rcsid[] = "$OpenBSD: fat.c,v 1.14 2006/04/02 21:38:56 djm Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -94,7 +94,7 @@ readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp)
int ret = FSOK;
boot->NumFree = boot->NumBad = 0;
- fat = malloc(sizeof(struct fatEntry) * boot->NumClusters);
+ fat = calloc(boot->NumClusters, sizeof(struct fatEntry));
buffer = malloc(boot->FATsecs * boot->BytesPerSec);
if (fat == NULL || buffer == NULL) {
perror("No space for FAT");
@@ -103,8 +103,6 @@ readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp)
return (FSFATAL);
}
- (void)memset(fat, 0, sizeof(struct fatEntry) * boot->NumClusters);
-
off = boot->ResSectors + no * boot->FATsecs;
off *= boot->BytesPerSec;
diff --git a/sbin/raidctl/raidctl.c b/sbin/raidctl/raidctl.c
index c1cf113bc42..0c0de03da39 100644
--- a/sbin/raidctl/raidctl.c
+++ b/sbin/raidctl/raidctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: raidctl.c,v 1.24 2005/11/14 17:17:11 deraadt Exp $ */
+/* $OpenBSD: raidctl.c,v 1.25 2006/04/02 21:38:56 djm Exp $ */
/* $NetBSD: raidctl.c,v 1.27 2001/07/10 01:30:52 lukem Exp $ */
/*-
@@ -964,8 +964,9 @@ do_meter(fdidpair *fds, int nfd, u_long option)
start_value = 0;
last_eta = 0;
progress_total = progress_completed = 0;
- progressInfo = malloc(nfd * sizeof(RF_ProgressInfo_t));
- memset(&progressInfo[0], 0, nfd * sizeof(RF_ProgressInfo_t));
+ progressInfo = calloc(nfd, sizeof(RF_ProgressInfo_t));
+ if (!progressInfo)
+ err(1, "calloc");
if (gettimeofday(&start_time, NULL))
err(1, "gettimeofday");
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index bb6844c5d77..bd28936e982 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sysctl.c,v 1.133 2005/11/30 15:46:32 dlg Exp $ */
+/* $OpenBSD: sysctl.c,v 1.134 2006/04/02 21:38:56 djm Exp $ */
/* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */
/*
@@ -40,7 +40,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95";
#else
-static const char rcsid[] = "$OpenBSD: sysctl.c,v 1.133 2005/11/30 15:46:32 dlg Exp $";
+static const char rcsid[] = "$OpenBSD: sysctl.c,v 1.134 2006/04/02 21:38:56 djm Exp $";
#endif
#endif /* not lint */
@@ -1146,20 +1146,17 @@ vfsinit(void)
if (sysctl(mib, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0)
return;
maxtypenum++; /* + generic */
- if ((vfs_typenums = malloc(maxtypenum * sizeof(int))) == NULL)
+ if ((vfs_typenums = calloc(maxtypenum, sizeof(int))) == NULL)
return;
- memset(vfs_typenums, 0, maxtypenum * sizeof(int));
- if ((vfsvars = malloc(maxtypenum * sizeof(*vfsvars))) == NULL) {
+ if ((vfsvars = calloc(maxtypenum, sizeof(*vfsvars))) == NULL) {
free(vfs_typenums);
return;
}
- memset(vfsvars, 0, maxtypenum * sizeof(*vfsvars));
- if ((vfsname = malloc(maxtypenum * sizeof(*vfsname))) == NULL) {
+ if ((vfsname = calloc(maxtypenum, sizeof(*vfsname))) == NULL) {
free(vfs_typenums);
free(vfsvars);
return;
}
- memset(vfsname, 0, maxtypenum * sizeof(*vfsname));
mib[2] = VFS_CONF;
buflen = sizeof vfc;
for (loc = lastused, cnt = 1; cnt < maxtypenum; cnt++) {
diff --git a/usr.bin/apropos/apropos.c b/usr.bin/apropos/apropos.c
index d680b7e44bc..86b8903adbe 100644
--- a/usr.bin/apropos/apropos.c
+++ b/usr.bin/apropos/apropos.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apropos.c,v 1.11 2005/10/17 19:04:19 otto Exp $ */
+/* $OpenBSD: apropos.c,v 1.12 2006/04/02 21:38:56 djm Exp $ */
/* $NetBSD: apropos.c,v 1.5 1995/09/04 20:46:20 tls Exp $ */
/*
@@ -40,7 +40,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)apropos.c 8.8 (Berkeley) 5/4/95";
#else
-static char rcsid[] = "$OpenBSD: apropos.c,v 1.11 2005/10/17 19:04:19 otto Exp $";
+static char rcsid[] = "$OpenBSD: apropos.c,v 1.12 2006/04/02 21:38:56 djm Exp $";
#endif
#endif /* not lint */
@@ -99,9 +99,8 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
- if ((found = malloc((u_int)argc * sizeof(int))) == NULL)
+ if ((found = calloc(argc, sizeof(int))) == NULL)
err(1, NULL);
- memset(found, 0, argc * sizeof(int));
for (p = argv; *p; ++p) /* convert to lower-case */
lowstr(*p, *p);
diff --git a/usr.bin/elf2aout/elf2aout.c b/usr.bin/elf2aout/elf2aout.c
index dd714bfe98b..acca8a6cbc8 100644
--- a/usr.bin/elf2aout/elf2aout.c
+++ b/usr.bin/elf2aout/elf2aout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: elf2aout.c,v 1.5 2004/03/16 01:11:09 tedu Exp $ */
+/* $OpenBSD: elf2aout.c,v 1.6 2006/04/02 21:38:56 djm Exp $ */
/*
* Copyright (c) 1995
@@ -129,12 +129,11 @@ usage:
* Find space for a table matching ELF section indices to a.out
* symbol types.
*/
- symTypeTable = (int *) malloc(ex.e_shnum * sizeof(int));
+ symTypeTable = calloc(ex.e_shnum, sizeof(int));
if (!symTypeTable) {
fprintf(stderr, "symTypeTable: can't allocate.\n");
exit(1);
}
- memset(symTypeTable, 0, ex.e_shnum * sizeof(int));
/*
* Look for the symbol table and string table... Also map section
diff --git a/usr.bin/whatis/whatis.c b/usr.bin/whatis/whatis.c
index ddd74440a6f..deb977e41cf 100644
--- a/usr.bin/whatis/whatis.c
+++ b/usr.bin/whatis/whatis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: whatis.c,v 1.10 2005/10/17 19:04:20 otto Exp $ */
+/* $OpenBSD: whatis.c,v 1.11 2006/04/02 21:38:56 djm Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -93,9 +93,8 @@ main(int argc, char *argv[])
if (argc < 1)
usage();
- if ((found = malloc((u_int)argc * sizeof(int))) == NULL)
+ if ((found = calloc(argc, sizeof(int))) == NULL)
err(1, NULL);
- memset(found, 0, argc * sizeof(int));
for (p = argv; *p; ++p) /* trim full paths */
if ((beg = strrchr(*p, '/')))
diff --git a/usr.sbin/afs/src/arlad/messages.c b/usr.sbin/afs/src/arlad/messages.c
index fa5848c8a57..458e3ce03d3 100644
--- a/usr.sbin/afs/src/arlad/messages.c
+++ b/usr.sbin/afs/src/arlad/messages.c
@@ -2895,11 +2895,9 @@ vioc_new_cell(int fd, struct nnpfs_message_pioctl *h, u_int size)
for (count = 0; *hp != 0; ++hp)
++count;
- dbs = malloc (count * sizeof(*dbs));
+ dbs = calloc (count, sizeof(*dbs));
if (dbs == NULL)
return nnpfs_send_message_wakeup (fd, h->header.sequence_num, ENOMEM);
-
- memset(dbs, 0, count * sizeof(*dbs));
hp = (uint32_t *)h->msg;
for (i = 0; i < count; ++i) {
diff --git a/usr.sbin/afs/src/arlad/volcache.c b/usr.sbin/afs/src/arlad/volcache.c
index 27b543f10eb..1fb027dad74 100644
--- a/usr.sbin/afs/src/arlad/volcache.c
+++ b/usr.sbin/afs/src/arlad/volcache.c
@@ -183,10 +183,9 @@ create_new_entries (unsigned n)
VolCacheEntry *entries;
int i;
- entries = (VolCacheEntry *)malloc (n * sizeof(VolCacheEntry));
+ entries = calloc (n, sizeof(VolCacheEntry));
if (entries == NULL)
- arla_errx (1, ADEBERROR, "volcache: malloc failed");
- memset(entries, 0, n * sizeof(VolCacheEntry));
+ arla_errx (1, ADEBERROR, "volcache: calloc failed");
for (i = 0; i < n; ++i) {
entries[i].cell = -1;
diff --git a/usr.sbin/afs/src/lib/ko/agetarg.c b/usr.sbin/afs/src/lib/ko/agetarg.c
index 51a52bb4cf3..b8cb3eae672 100644
--- a/usr.sbin/afs/src/lib/ko/agetarg.c
+++ b/usr.sbin/afs/src/lib/ko/agetarg.c
@@ -454,10 +454,9 @@ agetarg(struct agetargs *args,
for(i = 0 ; args[i].type != aarg_end; i++)
num_args++;
- usedargs = malloc (num_args * sizeof(char));
+ usedargs = calloc (num_args, sizeof(char));
if (usedargs == NULL)
return ENOMEM;
- memset (usedargs, 0, num_args *sizeof(char));
srand (time(NULL));
(*optind)++;
diff --git a/usr.sbin/afs/src/milko/lib/ropa/ropa.c b/usr.sbin/afs/src/milko/lib/ropa/ropa.c
index 4994801acd7..dc819406348 100644
--- a/usr.sbin/afs/src/milko/lib/ropa/ropa.c
+++ b/usr.sbin/afs/src/milko/lib/ropa/ropa.c
@@ -391,10 +391,9 @@ create_clients (unsigned n)
struct ropa_client *c;
unsigned long i;
- c = malloc (n * sizeof (*c));
+ c = calloc (n, sizeof (*c));
if (c == NULL)
- err (1, "create_clients: malloc");
- memset (c, 0, n * sizeof (*c));
+ err (1, "create_clients: calloc");
for (i = 0 ; i < n; i++) {
#ifdef DIAGNOSTIC
diff --git a/usr.sbin/bind/lib/lwres/getipnode.c b/usr.sbin/bind/lib/lwres/getipnode.c
index 8a11b474a3c..6d9b6669922 100644
--- a/usr.sbin/bind/lib/lwres/getipnode.c
+++ b/usr.sbin/bind/lib/lwres/getipnode.c
@@ -753,10 +753,9 @@ copyandmerge(struct hostent *he1, struct hostent *he2, int af, int *error_num)
if (he == NULL)
goto no_recovery;
- he->h_addr_list = malloc(sizeof(char *) * (addresses));
+ he->h_addr_list = calloc(addresses, sizeof(char *));
if (he->h_addr_list == NULL)
goto cleanup0;
- memset(he->h_addr_list, 0, sizeof(char *) * (addresses));
/*
* Copy addresses.
diff --git a/usr.sbin/route6d/route6d.c b/usr.sbin/route6d/route6d.c
index 1c4c389b663..ad0ee22f25f 100644
--- a/usr.sbin/route6d/route6d.c
+++ b/usr.sbin/route6d/route6d.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route6d.c,v 1.43 2006/02/06 17:51:30 jmc Exp $ */
+/* $OpenBSD: route6d.c,v 1.44 2006/04/02 21:38:55 djm Exp $ */
/* $KAME: route6d.c,v 1.94 2002/10/26 20:08:55 itojun Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#if 0
-static char _rcsid[] = "$OpenBSD: route6d.c,v 1.43 2006/02/06 17:51:30 jmc Exp $";
+static char _rcsid[] = "$OpenBSD: route6d.c,v 1.44 2006/04/02 21:38:55 djm Exp $";
#endif
#include <stdio.h>
@@ -3409,13 +3409,11 @@ setindex2ifc(int idx, struct ifc *ifcp)
if (!index2ifc) {
nindex2ifc = 5; /*initial guess*/
- index2ifc = (struct ifc **)
- malloc(sizeof(*index2ifc) * nindex2ifc);
+ index2ifc = calloc(nindex2ifc, sizeof(*index2ifc));
if (index2ifc == NULL) {
- fatal("malloc");
+ fatal("calloc");
/*NOTREACHED*/
}
- memset(index2ifc, 0, sizeof(*index2ifc) * nindex2ifc);
}
n = nindex2ifc;
while (nindex2ifc <= idx)