From 6ebd04219f0d749c87a763e8afb578dfcd5223cc Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 2 Sep 2007 15:19:41 +0000 Subject: use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg --- bin/df/df.c | 6 +++--- bin/ed/undo.c | 6 +++--- bin/pax/tables.c | 6 +++--- bin/systrace/systrace.c | 4 ++-- games/worms/worms.c | 12 ++++++------ lib/libc/gen/getnetgrent.c | 4 ++-- lib/libc/gen/login_cap.c | 4 ++-- lib/libc/gen/scandir.c | 4 ++-- lib/libc/gen/setmode.c | 4 ++-- lib/libc/gen/strtofflags.c | 4 ++-- lib/libc/net/getprotoent.c | 4 ++-- lib/libc/net/getservent.c | 4 ++-- lib/libc/net/rcmdsh.c | 4 ++-- lib/libc/regex/regcomp.c | 6 +++--- lib/libc/rpc/pmap_rmt.c | 4 ++-- lib/libc/stdlib/hcreate.c | 4 ++-- lib/libc/stdlib/radixsort.c | 4 ++-- lib/libc/string/bm.c | 4 ++-- lib/libevent/kqueue.c | 6 +++--- lib/libpcap/optimize.c | 12 ++++++------ lib/libpcap/pcap.c | 4 ++-- libexec/ftpd/ftpd.c | 8 ++++---- libexec/ld.so/ldconfig/prebind.c | 6 +++--- libexec/spamd-setup/spamd-setup.c | 6 +++--- libexec/spamd/sdl.c | 4 ++-- sbin/atactl/atactl.c | 6 +++--- sbin/ccdconfig/ccdconfig.c | 4 ++-- sbin/dhclient/dhclient.c | 4 ++-- sbin/disklabel/editor.c | 6 +++--- sbin/dump/main.c | 6 +++--- sbin/fsck_ext2fs/setup.c | 4 ++-- sbin/fsck_msdos/fat.c | 9 +++++---- sbin/ifconfig/ifconfig.c | 6 +++--- sbin/isakmpd/ipsec.c | 4 ++-- sbin/isakmpd/pf_key_v2.c | 4 ++-- sbin/isakmpd/sa.c | 4 ++-- sbin/isakmpd/x509.c | 6 +++--- sbin/mount/mount.c | 8 ++++---- sbin/mount_vnd/pkcs5_pbkdf2.c | 2 +- sbin/raidctl/raidctl.c | 6 +++--- sbin/restore/interactive.c | 6 +++--- sbin/restore/main.c | 6 +++--- sbin/restore/tape.c | 6 +++--- sbin/umount/umount.c | 6 +++--- usr.bin/asn1_compile/gen_copy.c | 2 +- usr.bin/at/at.c | 12 ++++++------ usr.bin/awk/b.c | 6 +++--- usr.bin/awk/lib.c | 4 ++-- usr.bin/bdes/bdes.c | 6 +++--- usr.bin/cdio/cddb.c | 4 ++-- usr.bin/file/magic.c | 7 ++++--- usr.bin/finger/sprint.c | 6 +++--- usr.bin/fsplit/fsplit.c | 6 +++--- usr.bin/fstat/fstat.c | 6 +++--- usr.bin/ftp/stringlist.c | 6 +++--- usr.bin/grep/grep.c | 6 +++--- usr.bin/grep/grep.h | 3 ++- usr.bin/grep/util.c | 12 +++++++++++- usr.bin/indent/lexi.c | 6 +++--- usr.bin/locate/locate/util.c | 6 +++--- usr.bin/midiplay/midiplay.c | 4 ++-- usr.bin/nm/elf.c | 10 +++++----- usr.bin/nm/nm.c | 8 ++++---- usr.bin/patch/pch.c | 10 +++++----- usr.bin/pmdb/clit.c | 4 ++-- usr.bin/rs/rs.c | 6 +++--- usr.bin/rusers/rusers.c | 10 +++++----- usr.bin/sdiff/sdiff.c | 4 ++-- usr.bin/spell/spellprog.c | 6 +++--- usr.bin/strip/strip.c | 6 +++--- usr.bin/sudo/parse.yacc | 2 +- usr.bin/sup/src/scm.c | 4 ++-- usr.bin/systat/pigs.c | 7 +++---- usr.bin/vi/cl/cl_read.c | 4 ++-- usr.bin/vi/ex/ex_script.c | 4 ++-- usr.bin/window/compress.c | 20 ++++++++++---------- usr.bin/window/wwinit.c | 6 +++--- usr.bin/window/wwopen.c | 6 +++--- usr.bin/window/wwsize.c | 6 +++--- usr.bin/window/xx.c | 6 +++--- usr.bin/xargs/xargs.c | 8 ++++---- usr.bin/yacc/skeleton.c | 8 ++++---- usr.sbin/cron/env.c | 6 +++--- usr.sbin/dhcrelay/dispatch.c | 4 ++-- usr.sbin/kvm_mkdb/nlist.c | 6 +++--- usr.sbin/lpr/common_source/common.c | 6 +++--- usr.sbin/lpr/lpd/lpd.c | 6 +++--- usr.sbin/lpr/lpd/printjob.c | 4 ++-- usr.sbin/lpr/pac/pac.c | 6 +++--- usr.sbin/mailwrapper/mailwrapper.c | 4 ++-- usr.sbin/memconfig/memconfig.c | 4 ++-- usr.sbin/mrinfo/mrinfo.c | 4 ++-- usr.sbin/ppp/ppp/route.c | 4 ++-- usr.sbin/pppd/main.c | 6 +++--- usr.sbin/procmap/procmap.c | 4 ++-- usr.sbin/pstat/pstat.c | 6 +++--- usr.sbin/quot/quot.c | 6 +++--- usr.sbin/sasyncd/pfkey.c | 6 +++--- 98 files changed, 289 insertions(+), 277 deletions(-) diff --git a/bin/df/df.c b/bin/df/df.c index acbeb334a6d..9c9c08b562e 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -1,4 +1,4 @@ -/* $OpenBSD: df.c,v 1.46 2006/10/29 19:20:01 otto Exp $ */ +/* $OpenBSD: df.c,v 1.47 2007/09/02 15:19:07 deraadt Exp $ */ /* $NetBSD: df.c,v 1.21.2.1 1995/11/01 00:06:11 jtc Exp $ */ /* @@ -45,7 +45,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)df.c 8.7 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: df.c,v 1.46 2006/10/29 19:20:01 otto Exp $"; +static char rcsid[] = "$OpenBSD: df.c,v 1.47 2007/09/02 15:19:07 deraadt Exp $"; #endif #endif /* not lint */ @@ -248,7 +248,7 @@ maketypelist(char *fslist) ++nextcp; /* Build an array of that many types. */ - if ((av = typelist = malloc((i + 1) * sizeof(char *))) == NULL) + if ((av = typelist = calloc(i + 1, sizeof(char *))) == NULL) err(1, NULL); av[0] = fslist; for (i = 1, nextcp = fslist; (nextcp = strchr(nextcp, ',')) != NULL; i++) { diff --git a/bin/ed/undo.c b/bin/ed/undo.c index 473dd41e404..c01dc191ee1 100644 --- a/bin/ed/undo.c +++ b/bin/ed/undo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: undo.c,v 1.8 2003/06/11 23:42:12 deraadt Exp $ */ +/* $OpenBSD: undo.c,v 1.9 2007/09/02 15:19:07 deraadt Exp $ */ /* $NetBSD: undo.c,v 1.2 1995/03/21 09:04:52 cgd Exp $ */ /* undo.c: This file contains the undo routines for the ed line editor */ @@ -32,7 +32,7 @@ #if 0 static char *rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp"; #else -static char rcsid[] = "$OpenBSD: undo.c,v 1.8 2003/06/11 23:42:12 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: undo.c,v 1.9 2007/09/02 15:19:07 deraadt Exp $"; #endif #endif /* not lint */ @@ -52,7 +52,7 @@ push_undo_stack(int type, int from, int to) #if defined(sun) || defined(NO_REALLOC_NULL) if (ustack == NULL && - (ustack = (undo_t *) malloc((usize = USIZE) * sizeof(undo_t))) == NULL) { + (ustack = (undo_t *) calloc((usize = USIZE), sizeof(undo_t))) == NULL) { perror(NULL); seterrmsg("out of memory"); return NULL; diff --git a/bin/pax/tables.c b/bin/pax/tables.c index 2705b319c33..e428051c3da 100644 --- a/bin/pax/tables.c +++ b/bin/pax/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.24 2006/11/17 08:38:04 otto Exp $ */ +/* $OpenBSD: tables.c,v 1.25 2007/09/02 15:19:08 deraadt Exp $ */ /* $NetBSD: tables.c,v 1.4 1995/03/21 09:07:45 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 5/31/93"; #else -static const char rcsid[] = "$OpenBSD: tables.c,v 1.24 2006/11/17 08:38:04 otto Exp $"; +static const char rcsid[] = "$OpenBSD: tables.c,v 1.25 2007/09/02 15:19:08 deraadt Exp $"; #endif #endif /* not lint */ @@ -1102,7 +1102,7 @@ dir_start(void) return(0); dirsize = DIRP_SIZE; - if ((dirp = malloc(dirsize * sizeof(DIRDATA))) == NULL) { + if ((dirp = calloc(dirsize, sizeof(DIRDATA))) == NULL) { paxwarn(1, "Unable to allocate memory for directory times"); return(-1); } diff --git a/bin/systrace/systrace.c b/bin/systrace/systrace.c index 37a52712f5c..8e2045c564a 100644 --- a/bin/systrace/systrace.c +++ b/bin/systrace/systrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: systrace.c,v 1.54 2006/07/02 12:34:15 sturm Exp $ */ +/* $OpenBSD: systrace.c,v 1.55 2007/09/02 15:19:08 deraadt Exp $ */ /* * Copyright 2002 Niels Provos * All rights reserved. @@ -754,7 +754,7 @@ main(int argc, char **argv) if (pidattach == 0) { /* Run a command and attach to it */ - if ((args = malloc((argc + 1) * sizeof(char *))) == NULL) + if ((args = calloc(argc + 1, sizeof(char *))) == NULL) err(1, "malloc"); for (i = 0; i < argc; i++) diff --git a/games/worms/worms.c b/games/worms/worms.c index 4448f2cdde1..89eb0418787 100644 --- a/games/worms/worms.c +++ b/games/worms/worms.c @@ -1,4 +1,4 @@ -/* $OpenBSD: worms.c,v 1.17 2004/11/29 08:52:29 jsg Exp $ */ +/* $OpenBSD: worms.c,v 1.18 2007/09/02 15:19:09 deraadt Exp $ */ /* * Copyright (c) 1980, 1993 @@ -39,7 +39,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)worms.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: worms.c,v 1.17 2004/11/29 08:52:29 jsg Exp $"; +static char rcsid[] = "$OpenBSD: worms.c,v 1.18 2007/09/02 15:19:09 deraadt Exp $"; #endif #endif /* not lint */ @@ -236,7 +236,7 @@ main(int argc, char *argv[]) } srandomdev(); - if (!(worm = malloc((size_t)number * sizeof(struct worm)))) + if (!(worm = calloc((size_t)number, sizeof(struct worm)))) nomem(); initscr(); curs_set(0); @@ -245,7 +245,7 @@ main(int argc, char *argv[]) last = CO - 1; bottom = LI - 1; if (!(ip = malloc((size_t)(LI * CO * sizeof(short)))) || - !(ref = malloc((size_t)(LI * sizeof(short *))))) { + !(ref = calloc((size_t)LI, sizeof(short *)))) { endwin(); nomem(); } @@ -257,14 +257,14 @@ main(int argc, char *argv[]) *ip++ = 0; for (n = number, w = &worm[0]; --n >= 0; w++) { w->orientation = w->head = 0; - if (!(ip = malloc((size_t)(length * sizeof(short))))) { + if (!(ip = calloc((size_t)length, sizeof(short)))) { endwin(); nomem(); } w->xpos = ip; for (x = length; --x >= 0;) *ip++ = -1; - if (!(ip = malloc((size_t)(length * sizeof(short))))) { + if (!(ip = calloc((size_t)length, sizeof(short)))) { endwin(); nomem(); } diff --git a/lib/libc/gen/getnetgrent.c b/lib/libc/gen/getnetgrent.c index 51493ed422c..937ce158d1e 100644 --- a/lib/libc/gen/getnetgrent.c +++ b/lib/libc/gen/getnetgrent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetgrent.c,v 1.18 2007/03/05 20:29:14 millert Exp $ */ +/* $OpenBSD: getnetgrent.c,v 1.19 2007/09/02 15:19:16 deraadt Exp $ */ /* * Copyright (c) 1994 Christos Zoulas @@ -88,7 +88,7 @@ _ng_sl_init(void) sl->sl_cur = 0; sl->sl_max = 20; - sl->sl_str = malloc(sl->sl_max * sizeof(char *)); + sl->sl_str = calloc(sl->sl_max, sizeof(char *)); if (sl->sl_str == NULL) return NULL; return sl; diff --git a/lib/libc/gen/login_cap.c b/lib/libc/gen/login_cap.c index de8b048c349..fb6a7e0df8b 100644 --- a/lib/libc/gen/login_cap.c +++ b/lib/libc/gen/login_cap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: login_cap.c,v 1.26 2006/04/09 04:40:35 deraadt Exp $ */ +/* $OpenBSD: login_cap.c,v 1.27 2007/09/02 15:19:16 deraadt Exp $ */ /* * Copyright (c) 2000-2004 Todd C. Miller @@ -180,7 +180,7 @@ login_getstyle(login_cap_t *lc, char *style, char *atype) while (*ta) if (*ta++ == ',') ++i; - f2 = authtypes = malloc(sizeof(char *) * i); + f2 = authtypes = calloc(sizeof(char *), i); if (!authtypes) { syslog(LOG_ERR, "malloc: %m"); free(f1); diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 089ad19e0da..2ad8c3e612e 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scandir.c,v 1.11 2007/06/26 05:00:50 ray Exp $ */ +/* $OpenBSD: scandir.c,v 1.12 2007/09/02 15:19:16 deraadt Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -78,7 +78,7 @@ scandir(const char *dirname, struct dirent ***namelist, errno = ENOMEM; goto fail; } - names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *)); + names = (struct dirent **)calloc(arraysz, sizeof(struct dirent *)); if (names == NULL) goto fail; diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 843b46183c9..9cc2cbc59ba 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setmode.c,v 1.19 2006/03/12 18:36:46 otto Exp $ */ +/* $OpenBSD: setmode.c,v 1.20 2007/09/02 15:19:16 deraadt Exp $ */ /* $NetBSD: setmode.c,v 1.15 1997/02/07 22:21:06 christos Exp $ */ /* @@ -187,7 +187,7 @@ setmode(const char *p) setlen = SET_LEN + 2; - if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL) + if ((set = calloc((u_int)sizeof(BITCMD), setlen)) == NULL) return (NULL); saveset = set; endset = set + (setlen - 2); diff --git a/lib/libc/gen/strtofflags.c b/lib/libc/gen/strtofflags.c index 9eba0f4517d..a54fd2ce843 100644 --- a/lib/libc/gen/strtofflags.c +++ b/lib/libc/gen/strtofflags.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strtofflags.c,v 1.5 2005/08/08 08:05:34 espie Exp $ */ +/* $OpenBSD: strtofflags.c,v 1.6 2007/09/02 15:19:16 deraadt Exp $ */ /*- * Copyright (c) 1993 @@ -82,7 +82,7 @@ fflagstostr(u_int32_t flags) u_int32_t setflags; int i; - if ((string = (char *)malloc(nmappings * (longestflaglen + 1))) == NULL) + if ((string = (char *)calloc(nmappings, longestflaglen + 1)) == NULL) return (NULL); setflags = flags; diff --git a/lib/libc/net/getprotoent.c b/lib/libc/net/getprotoent.c index 7c6ab681664..f0705e0765e 100644 --- a/lib/libc/net/getprotoent.c +++ b/lib/libc/net/getprotoent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getprotoent.c,v 1.9 2006/01/17 15:41:52 millert Exp $ */ +/* $OpenBSD: getprotoent.c,v 1.10 2007/09/02 15:19:17 deraadt Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -102,7 +102,7 @@ again: pe->p_proto = l; if (pd->aliases == NULL) { pd->maxaliases = 5; - pd->aliases = malloc(pd->maxaliases * sizeof(char *)); + pd->aliases = calloc(pd->maxaliases, sizeof(char *)); if (pd->aliases == NULL) { serrno = errno; endprotoent_r(pd); diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c index ab916b8e80f..c81a4cf3e29 100644 --- a/lib/libc/net/getservent.c +++ b/lib/libc/net/getservent.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getservent.c,v 1.11 2006/01/17 15:41:52 millert Exp $ */ +/* $OpenBSD: getservent.c,v 1.12 2007/09/02 15:19:17 deraadt Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -104,7 +104,7 @@ again: se->s_proto = cp; if (sd->aliases == NULL) { sd->maxaliases = 10; - sd->aliases = malloc(sd->maxaliases * sizeof(char *)); + sd->aliases = calloc(sd->maxaliases, sizeof(char *)); if (sd->aliases == NULL) { serrno = errno; endservent_r(sd); diff --git a/lib/libc/net/rcmdsh.c b/lib/libc/net/rcmdsh.c index 34a228d1e95..a472162711b 100644 --- a/lib/libc/net/rcmdsh.c +++ b/lib/libc/net/rcmdsh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcmdsh.c,v 1.11 2005/08/06 20:30:03 espie Exp $ */ +/* $OpenBSD: rcmdsh.c,v 1.12 2007/09/02 15:19:17 deraadt Exp $ */ /* * Copyright (c) 2001, MagniComp @@ -151,7 +151,7 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser, for (n = 7; (p = strchr(++p, ' ')) != NULL; n++) continue; rshprog = strdup(rshprog); - ap = argv = malloc(sizeof(char *) * n); + ap = argv = calloc(sizeof(char *), n); if (rshprog == NULL || argv == NULL) { perror("rcmdsh"); _exit(255); diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 402c64056f3..83b1dfbd67a 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: regcomp.c,v 1.16 2006/03/31 05:36:36 deraadt Exp $ */ +/* $OpenBSD: regcomp.c,v 1.17 2007/09/02 15:19:17 deraadt Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 Henry Spencer. * Copyright (c) 1992, 1993, 1994 @@ -176,7 +176,7 @@ regcomp(regex_t *preg, const char *pattern, int cflags) if (g == NULL) return(REG_ESPACE); p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ - p->strip = (sop *)malloc(p->ssize * sizeof(sop)); + p->strip = (sop *)calloc(p->ssize, sizeof(sop)); p->slen = 0; if (p->strip == NULL) { free((char *)g); @@ -1031,7 +1031,7 @@ allocset(struct parse *p) assert(nc % CHAR_BIT == 0); nbytes = nc / CHAR_BIT * css; if (p->g->sets == NULL) - p->g->sets = (cset *)malloc(nc * sizeof(cset)); + p->g->sets = (cset *)calloc(nc, sizeof(cset)); else { cset *ptr; ptr = (cset *)realloc((char *)p->g->sets, diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c index 76adaddd2a3..2265041a797 100644 --- a/lib/libc/rpc/pmap_rmt.c +++ b/lib/libc/rpc/pmap_rmt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap_rmt.c,v 1.27 2006/09/22 18:42:04 otto Exp $ */ +/* $OpenBSD: pmap_rmt.c,v 1.28 2007/09/02 15:19:17 deraadt Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape @@ -172,7 +172,7 @@ newgetbroadcastnets(struct in_addr **addrsp) } } - addrs = (struct in_addr *)malloc(n * sizeof(*addrs)); + addrs = (struct in_addr *)calloc(n, sizeof(*addrs)); if (addrs == NULL) { freeifaddrs(ifap); return 0; diff --git a/lib/libc/stdlib/hcreate.c b/lib/libc/stdlib/hcreate.c index f8df1bcd7c9..094f32c173e 100644 --- a/lib/libc/stdlib/hcreate.c +++ b/lib/libc/stdlib/hcreate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hcreate.c,v 1.3 2005/10/10 17:37:44 espie Exp $ */ +/* $OpenBSD: hcreate.c,v 1.4 2007/09/02 15:19:17 deraadt Exp $ */ /* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */ /* @@ -117,7 +117,7 @@ hcreate(size_t nel) /* Allocate the table. */ htablesize = nel; - htable = malloc(htablesize * sizeof htable[0]); + htable = calloc(htablesize, sizeof htable[0]); if (htable == NULL) { errno = ENOMEM; return 0; diff --git a/lib/libc/stdlib/radixsort.c b/lib/libc/stdlib/radixsort.c index 0b2ff27044f..49d03b52d5d 100644 --- a/lib/libc/stdlib/radixsort.c +++ b/lib/libc/stdlib/radixsort.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radixsort.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: radixsort.c,v 1.9 2007/09/02 15:19:17 deraadt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -104,7 +104,7 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch) if (n < THRESHOLD) simplesort(a, n, 0, tr, endch); else { - if ((ta = malloc(n * sizeof(a))) == NULL) + if ((ta = calloc(n, sizeof(a))) == NULL) return (-1); r_sort_b(a, ta, n, 0, tr, endch); free(ta); diff --git a/lib/libc/string/bm.c b/lib/libc/string/bm.c index 829c24082e5..2c4c6ca7207 100644 --- a/lib/libc/string/bm.c +++ b/lib/libc/string/bm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bm.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: bm.c,v 1.7 2007/09/02 15:19:18 deraadt Exp $ */ /*- * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -104,7 +104,7 @@ bm_comp(u_char const *pb, size_t len, u_char const *freq) goto mem; memcpy(pat->pat, pb, pat->patlen); /* get skip delta */ - if ((pat->delta = malloc(256 * sizeof(*d))) == NULL) + if ((pat->delta = calloc(256, sizeof(*d))) == NULL) goto mem; for (j = 0, d = pat->delta; j < 256; j++) d[j] = pat->patlen; diff --git a/lib/libevent/kqueue.c b/lib/libevent/kqueue.c index c85334c29aa..89eb3356ad1 100644 --- a/lib/libevent/kqueue.c +++ b/lib/libevent/kqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kqueue.c,v 1.22 2007/03/19 15:12:49 millert Exp $ */ +/* $OpenBSD: kqueue.c,v 1.23 2007/09/02 15:19:18 deraadt Exp $ */ /* * Copyright 2000-2002 Niels Provos @@ -111,12 +111,12 @@ kq_init(void) kqueueop->kq = kq; /* Initalize fields */ - kqueueop->changes = malloc(NEVENT * sizeof(struct kevent)); + kqueueop->changes = calloc(NEVENT, sizeof(struct kevent)); if (kqueueop->changes == NULL) { free (kqueueop); return (NULL); } - kqueueop->events = malloc(NEVENT * sizeof(struct kevent)); + kqueueop->events = calloc(NEVENT, sizeof(struct kevent)); if (kqueueop->events == NULL) { free (kqueueop->changes); free (kqueueop); diff --git a/lib/libpcap/optimize.c b/lib/libpcap/optimize.c index 3c5fa1eb795..1e52e89bfd4 100644 --- a/lib/libpcap/optimize.c +++ b/lib/libpcap/optimize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: optimize.c,v 1.12 2006/04/02 21:38:57 djm Exp $ */ +/* $OpenBSD: optimize.c,v 1.13 2007/09/02 15:19:18 deraadt Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996 @@ -1806,7 +1806,7 @@ opt_init(root) */ unMarkAll(); n = count_blocks(root); - blocks = (struct block **)malloc(n * sizeof(*blocks)); + blocks = (struct block **)calloc(n, sizeof(*blocks)); if (blocks == NULL) bpf_error("malloc"); @@ -1815,14 +1815,14 @@ opt_init(root) number_blks_r(root); n_edges = 2 * n_blocks; - edges = (struct edge **)malloc(n_edges * sizeof(*edges)); + edges = (struct edge **)calloc(n_edges, sizeof(*edges)); if (edges == NULL) bpf_error("malloc"); /* * The number of levels is bounded by the number of nodes. */ - levels = (struct block **)malloc(n_blocks * sizeof(*levels)); + levels = (struct block **)calloc(n_blocks, sizeof(*levels)); if (levels == NULL) bpf_error("malloc"); @@ -1870,8 +1870,8 @@ opt_init(root) * we'll need. */ maxval = 3 * max_stmts; - vmap = (struct vmapinfo *)malloc(maxval * sizeof(*vmap)); - vnode_base = (struct valnode *)malloc(maxval * sizeof(*vmap)); + vmap = (struct vmapinfo *)calloc(maxval, sizeof(*vmap)); + vnode_base = (struct valnode *)calloc(maxval, sizeof(*vmap)); if (vmap == NULL || vnode_base == NULL) bpf_error("malloc"); } diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c index 6c516f39e32..9bf613921c0 100644 --- a/lib/libpcap/pcap.c +++ b/lib/libpcap/pcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap.c,v 1.10 2006/03/26 20:58:51 djm Exp $ */ +/* $OpenBSD: pcap.c,v 1.11 2007/09/02 15:19:18 deraadt Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 @@ -209,7 +209,7 @@ pcap_list_datalinks(pcap_t *p, int **dlt_buffer) **dlt_buffer = p->linktype; return (1); } else { - *dlt_buffer = (int*)malloc(sizeof(**dlt_buffer) * p->dlt_count); + *dlt_buffer = (int*)calloc(sizeof(**dlt_buffer), p->dlt_count); if (*dlt_buffer == NULL) { (void)snprintf(p->errbuf, sizeof(p->errbuf), "malloc: %s", pcap_strerror(errno)); diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index dc9ad211d89..21579c44ab1 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpd.c,v 1.180 2007/07/31 03:35:04 ray Exp $ */ +/* $OpenBSD: ftpd.c,v 1.181 2007/09/02 15:19:20 deraadt Exp $ */ /* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */ /* @@ -70,7 +70,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)ftpd.c 8.4 (Berkeley) 4/16/94"; #else static const char rcsid[] = - "$OpenBSD: ftpd.c,v 1.180 2007/07/31 03:35:04 ray Exp $"; + "$OpenBSD: ftpd.c,v 1.181 2007/09/02 15:19:20 deraadt Exp $"; #endif #endif /* not lint */ @@ -439,8 +439,8 @@ main(int argc, char *argv[]) for (res = res0; res; res = res->ai_next) n++; - fds = malloc(n * sizeof(int)); - pfds = malloc(n * sizeof(struct pollfd)); + fds = calloc(n, sizeof(int)); + pfds = calloc(n, sizeof(struct pollfd)); if (!fds || !pfds) { syslog(LOG_ERR, "%s", strerror(errno)); exit(1); diff --git a/libexec/ld.so/ldconfig/prebind.c b/libexec/ld.so/ldconfig/prebind.c index c4d2080fddc..2fdfc09dce0 100644 --- a/libexec/ld.so/ldconfig/prebind.c +++ b/libexec/ld.so/ldconfig/prebind.c @@ -1,4 +1,4 @@ -/* $OpenBSD: prebind.c,v 1.8 2006/11/13 13:13:14 drahn Exp $ */ +/* $OpenBSD: prebind.c,v 1.9 2007/09/02 15:19:20 deraadt Exp $ */ /* * Copyright (c) 2006 Dale Rahn * @@ -625,7 +625,7 @@ elf_load_object(void *pexe, const char *name) object->dyn.strtab = str; strt = str; - sym = malloc(object->nchains * sizeof(Elf_Sym)); + sym = calloc(object->nchains, sizeof(Elf_Sym)); if (sym == NULL) { printf("unable to allocate symtab for %s\n", name); @@ -1410,7 +1410,7 @@ void elf_init_objarray(void) { objarray_sz = 512; - objarray = xmalloc(sizeof (objarray[0]) * objarray_sz); + objarray = xcalloc(sizeof (objarray[0]), objarray_sz); } void diff --git a/libexec/spamd-setup/spamd-setup.c b/libexec/spamd-setup/spamd-setup.c index 4efcbc5f223..51041a50816 100644 --- a/libexec/spamd-setup/spamd-setup.c +++ b/libexec/spamd-setup/spamd-setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spamd-setup.c,v 1.32 2007/02/27 02:10:58 beck Exp $ */ +/* $OpenBSD: spamd-setup.c,v 1.33 2007/09/02 15:19:20 deraadt Exp $ */ /* * Copyright (c) 2003 Bob Beck. All rights reserved. @@ -311,7 +311,7 @@ open_file(char *method, char *file) return (i); } else if (strcmp(method, "exec") == 0) { len = strlen(file); - argv = malloc(len * sizeof(char *)); + argv = calloc(len, sizeof(char *)); if (argv == NULL) errx(1, "malloc failed"); for (ap = argv; ap < &argv[len - 1] && @@ -540,7 +540,7 @@ collapse_blacklist(struct bl *bl, size_t blc) if (blc == 0) return (NULL); - cl = malloc(((blc / 2) + 1) * sizeof(struct cidr)); + cl = calloc(((blc / 2) + 1), sizeof(struct cidr)); if (cl == NULL) { return (NULL); } diff --git a/libexec/spamd/sdl.c b/libexec/spamd/sdl.c index d3d08525748..4f88b5133aa 100644 --- a/libexec/spamd/sdl.c +++ b/libexec/spamd/sdl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdl.c,v 1.16 2007/03/26 16:36:18 beck Exp $ */ +/* $OpenBSD: sdl.c,v 1.17 2007/09/02 15:19:20 deraadt Exp $ */ /* * Copyright (c) 2003-2007 Bob Beck. All rights reserved. @@ -99,7 +99,7 @@ sdl_add(char *sdname, char *sdstring, char ** addrs, int addrc) * formatted v4 and v6 addrs, if they don't all convert correctly, the * add fails. Each address should be address/maskbits */ - blacklists[idx].addrs = malloc(addrc * sizeof(struct sdentry)); + blacklists[idx].addrs = calloc(addrc, sizeof(struct sdentry)); if (blacklists[idx].addrs == NULL) goto misc_error; diff --git a/sbin/atactl/atactl.c b/sbin/atactl/atactl.c index 602b2f8f04a..6f82264ac63 100644 --- a/sbin/atactl/atactl.c +++ b/sbin/atactl/atactl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: atactl.c,v 1.37 2006/10/02 19:30:19 jmc Exp $ */ +/* $OpenBSD: atactl.c,v 1.38 2007/09/02 15:19:23 deraadt Exp $ */ /* $NetBSD: atactl.c,v 1.4 1999/02/24 18:49:14 jwise Exp $ */ /*- @@ -1455,8 +1455,8 @@ device_smart_readlog(int argc, char *argv[]) * the latest one. */ nsect = nerr / 5 + (nerr % 5 != 0 ? 1 : 0); - if ((newbuf = (u_int8_t *)malloc(nsect * DEV_BSIZE)) == NULL) - err(1, "malloc()"); + if ((newbuf = (u_int8_t *)calloc(nsect, DEV_BSIZE)) == NULL) + err(1, "calloc()"); memset(&req, 0, sizeof(req)); req.flags = ATACMD_READ; req.command = ATAPI_SMART; diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c index e45ba95c7d9..4d9188f65c0 100644 --- a/sbin/ccdconfig/ccdconfig.c +++ b/sbin/ccdconfig/ccdconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ccdconfig.c,v 1.32 2007/08/06 19:16:05 sobrado Exp $ */ +/* $OpenBSD: ccdconfig.c,v 1.33 2007/09/02 15:19:23 deraadt Exp $ */ /* $NetBSD: ccdconfig.c,v 1.6 1996/05/16 07:11:18 thorpej Exp $ */ /*- @@ -278,7 +278,7 @@ do_single(int argc, char *argv[], int action) } /* Next is the list of disks to make the ccd from. */ - disks = malloc(argc * sizeof(char *)); + disks = calloc(argc, sizeof(char *)); if (disks == NULL) { warnx("no memory to configure ccd"); goto done; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 9f07d8fb8b3..b3f6df739cd 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.114 2007/08/14 15:29:18 stevesk Exp $ */ +/* $OpenBSD: dhclient.c,v 1.115 2007/09/02 15:19:23 deraadt Exp $ */ /* * Copyright 2004 Henning Brauer @@ -1571,7 +1571,7 @@ priv_script_init(char *reason, char *medium) client->scriptEnvsize = 100; if (client->scriptEnv == NULL) client->scriptEnv = - malloc(client->scriptEnvsize * sizeof(char *)); + calloc(client->scriptEnvsize, sizeof(char *)); if (client->scriptEnv == NULL) error("script_init: no memory for environment"); diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index a347a9ebf61..96881391201 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.124 2007/07/24 15:11:53 deraadt Exp $ */ +/* $OpenBSD: editor.c,v 1.125 2007/09/02 15:19:23 deraadt Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -17,7 +17,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.124 2007/07/24 15:11:53 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.125 2007/09/02 15:19:23 deraadt Exp $"; #endif /* not lint */ #include @@ -1428,7 +1428,7 @@ sort_partitions(struct disklabel *lp, u_int16_t *npart) } /* Create an array of pointers to the partition data */ - if ((spp = malloc(sizeof(struct partition *) * npartitions)) == NULL) + if ((spp = calloc(npartitions, sizeof(struct partition *))) == NULL) errx(4, "out of memory"); for (npartitions = 0, i = 0; i < lp->d_npartitions; i++) { if (lp->d_partitions[i].p_fstype != FS_UNUSED && diff --git a/sbin/dump/main.c b/sbin/dump/main.c index ce24fd1224c..8995809a03d 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.41 2007/06/03 20:16:08 millert Exp $ */ +/* $OpenBSD: main.c,v 1.42 2007/09/02 15:19:23 deraadt Exp $ */ /* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 4/15/94"; #else -static const char rcsid[] = "$OpenBSD: main.c,v 1.41 2007/06/03 20:16:08 millert Exp $"; +static const char rcsid[] = "$OpenBSD: main.c,v 1.42 2007/09/02 15:19:23 deraadt Exp $"; #endif #endif /* not lint */ @@ -652,7 +652,7 @@ obsolete(int *argcp, char **argvp[]) return; /* Allocate space for new arguments. */ - if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL || + if ((*argvp = nargv = calloc(argc + 1, sizeof(char *))) == NULL || (p = flagsp = malloc(strlen(ap) + 2)) == NULL) err(1, NULL); diff --git a/sbin/fsck_ext2fs/setup.c b/sbin/fsck_ext2fs/setup.c index e4c1637be70..06cc0dbdc82 100644 --- a/sbin/fsck_ext2fs/setup.c +++ b/sbin/fsck_ext2fs/setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setup.c,v 1.14 2007/05/29 06:28:15 otto Exp $ */ +/* $OpenBSD: setup.c,v 1.15 2007/09/02 15:19:23 deraadt Exp $ */ /* $NetBSD: setup.c,v 1.1 1997/06/11 11:22:01 bouyer Exp $ */ /* @@ -181,7 +181,7 @@ setup(char *dev) * read in the summary info. */ - sblock.e2fs_gd = malloc(sblock.e2fs_ngdb * sblock.e2fs_bsize); + sblock.e2fs_gd = calloc(sblock.e2fs_ngdb, sblock.e2fs_bsize); if (sblock.e2fs_gd == NULL) errexit("out of memory\n"); asked = 0; diff --git a/sbin/fsck_msdos/fat.c b/sbin/fsck_msdos/fat.c index 29db725dbec..b7c05b4f4c0 100644 --- a/sbin/fsck_msdos/fat.c +++ b/sbin/fsck_msdos/fat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fat.c,v 1.16 2006/11/11 11:34:32 pedro Exp $ */ +/* $OpenBSD: fat.c,v 1.17 2007/09/02 15:19:23 deraadt 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.16 2006/11/11 11:34:32 pedro Exp $"; +static char rcsid[] = "$OpenBSD: fat.c,v 1.17 2007/09/02 15:19:23 deraadt Exp $"; #endif /* not lint */ #include @@ -95,7 +95,7 @@ readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp) boot->NumFree = boot->NumBad = 0; fat = calloc(boot->NumClusters, sizeof(struct fatEntry)); - buffer = malloc(boot->FATsecs * boot->BytesPerSec); + buffer = calloc(boot->FATsecs, boot->BytesPerSec); if (fat == NULL || buffer == NULL) { xperror("No space for FAT"); if (fat != NULL) @@ -432,7 +432,8 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat) off_t off; int ret = FSOK; - buffer = malloc(fatsz = boot->FATsecs * boot->BytesPerSec); + fatsz = boot->FATsecs * boot->BytesPerSec; + buffer = calloc(boot->FATsecs, boot->BytesPerSec); if (buffer == NULL) { xperror("No space for FAT"); return (FSFATAL); diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 44cd952f52a..6e7c2df97e4 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.186 2007/08/25 20:05:30 henning Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.187 2007/09/02 15:19:23 deraadt Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -896,7 +896,7 @@ list_cloners(void) if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1) err(1, "SIOCIFGCLONERS for count"); - buf = malloc(ifcr.ifcr_total * IFNAMSIZ); + buf = calloc(ifcr.ifcr_total, IFNAMSIZ); if (buf == NULL) err(1, "unable to allocate cloner name buffer"); @@ -2307,7 +2307,7 @@ status(int link, struct sockaddr_dl *sdl) goto proto_status; } - media_list = (int *)malloc(ifmr.ifm_count * sizeof(int)); + media_list = (int *)calloc(ifmr.ifm_count, sizeof(int)); if (media_list == NULL) err(1, "malloc"); ifmr.ifm_ulist = media_list; diff --git a/sbin/isakmpd/ipsec.c b/sbin/isakmpd/ipsec.c index ca531d396d0..df423c22d78 100644 --- a/sbin/isakmpd/ipsec.c +++ b/sbin/isakmpd/ipsec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipsec.c,v 1.129 2007/07/31 20:59:33 hshoexer Exp $ */ +/* $OpenBSD: ipsec.c,v 1.130 2007/09/02 15:19:24 deraadt Exp $ */ /* $EOM: ipsec.c,v 1.143 2000/12/11 23:57:42 niklas Exp $ */ /* @@ -1632,7 +1632,7 @@ ipsec_handle_leftover_payload(struct message *msg, u_int8_t type, spisz, proto); return -1; } - spis = (u_int8_t *) malloc(nspis * spisz); + spis = (u_int8_t *) calloc(nspis, spisz); if (!spis) { log_error("ipsec_handle_leftover_payload: malloc " "(%d) failed", nspis * spisz); diff --git a/sbin/isakmpd/pf_key_v2.c b/sbin/isakmpd/pf_key_v2.c index 3efc74bc48b..7c55abb9e25 100644 --- a/sbin/isakmpd/pf_key_v2.c +++ b/sbin/isakmpd/pf_key_v2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf_key_v2.c,v 1.181 2007/05/27 18:31:30 claudio Exp $ */ +/* $OpenBSD: pf_key_v2.c,v 1.182 2007/09/02 15:19:24 deraadt Exp $ */ /* $EOM: pf_key_v2.c,v 1.79 2000/12/12 00:33:19 niklas Exp $ */ /* @@ -337,7 +337,7 @@ pf_key_v2_write(struct pf_key_v2_msg *pmsg) struct sadb_msg *msg = TAILQ_FIRST(pmsg)->seg; struct pf_key_v2_node *np = TAILQ_FIRST(pmsg); - iov = (struct iovec *) malloc(cnt * sizeof *iov); + iov = (struct iovec *) calloc(cnt, sizeof *iov); if (!iov) { log_error("pf_key_v2_write: malloc (%lu) failed", cnt * (unsigned long) sizeof *iov); diff --git a/sbin/isakmpd/sa.c b/sbin/isakmpd/sa.c index bf7c7b0f551..0bdcb2c4bb5 100644 --- a/sbin/isakmpd/sa.c +++ b/sbin/isakmpd/sa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sa.c,v 1.112 2007/06/02 01:29:12 pvalchev Exp $ */ +/* $OpenBSD: sa.c,v 1.113 2007/09/02 15:19:24 deraadt Exp $ */ /* $EOM: sa.c,v 1.112 2000/12/12 00:22:52 niklas Exp $ */ /* @@ -88,7 +88,7 @@ sa_init(void) int i; bucket_mask = (1 << INITIAL_BUCKET_BITS) - 1; - sa_tab = malloc((bucket_mask + 1) * sizeof(struct sa_list)); + sa_tab = calloc(bucket_mask + 1, sizeof(struct sa_list)); if (!sa_tab) log_fatal("sa_init: malloc (%lu) failed", (bucket_mask + 1) * (unsigned long)sizeof(struct sa_list)); diff --git a/sbin/isakmpd/x509.c b/sbin/isakmpd/x509.c index 5fc0f91dcef..dfbf6446017 100644 --- a/sbin/isakmpd/x509.c +++ b/sbin/isakmpd/x509.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509.c,v 1.110 2007/08/05 09:43:09 tom Exp $ */ +/* $OpenBSD: x509.c,v 1.111 2007/09/02 15:19:24 deraadt Exp $ */ /* $EOM: x509.c,v 1.54 2001/01/16 18:42:16 ho Exp $ */ /* @@ -482,7 +482,7 @@ x509_hash_init(void) } free(x509_tab); } - x509_tab = malloc((bucket_mask + 1) * sizeof(struct x509_list)); + x509_tab = calloc(bucket_mask + 1, sizeof(struct x509_list)); if (!x509_tab) log_fatal("x509_hash_init: malloc (%lu) failed", (bucket_mask + 1) * @@ -1149,7 +1149,7 @@ x509_cert_get_subjects(void *scert, int *cnt, u_int8_t ***id, *cnt * (unsigned long)sizeof **id); goto fail; } - *id_len = malloc(*cnt * sizeof **id_len); + *id_len = calloc(*cnt, sizeof **id_len); if (!*id_len) { log_print("x509_cert_get_subject: malloc (%lu) failed", *cnt * (unsigned long)sizeof **id_len); diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c index a64b98b50b6..9b99c559a25 100644 --- a/sbin/mount/mount.c +++ b/sbin/mount/mount.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mount.c,v 1.45 2007/06/01 05:37:14 deraadt Exp $ */ +/* $OpenBSD: mount.c,v 1.46 2007/09/02 15:19:24 deraadt Exp $ */ /* $NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94"; #else -static char rcsid[] = "$OpenBSD: mount.c,v 1.45 2007/06/01 05:37:14 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mount.c,v 1.46 2007/09/02 15:19:24 deraadt Exp $"; #endif #endif /* not lint */ @@ -390,7 +390,7 @@ mountfs(const char *vfstype, const char *spec, const char *name, } argvsize = 64; - if((argv = malloc(argvsize * sizeof(char*))) == NULL) + if((argv = calloc(argvsize, sizeof(char *))) == NULL) err(1, "malloc"); argc = 0; argv[argc++] = NULL; /* this should be a full path name */ @@ -652,7 +652,7 @@ maketypelist(char *fslist) ++nextcp; /* Build an array of that many types. */ - if ((av = typelist = malloc((i + 1) * sizeof(char *))) == NULL) + if ((av = typelist = calloc(i + 1, sizeof(char *))) == NULL) err(1, NULL); av[0] = fslist; for (i = 1, nextcp = fslist; (nextcp = strchr(nextcp, ',')); i++) { diff --git a/sbin/mount_vnd/pkcs5_pbkdf2.c b/sbin/mount_vnd/pkcs5_pbkdf2.c index b88ee815b8e..75e9f7ac705 100644 --- a/sbin/mount_vnd/pkcs5_pbkdf2.c +++ b/sbin/mount_vnd/pkcs5_pbkdf2.c @@ -155,7 +155,7 @@ pkcs5_pbkdf2(u_int8_t **r, int dkLen, const u_int8_t *P, int Plen, l = (dkLen + PRF_BLOCKLEN - 1) / PRF_BLOCKLEN; /* allocate the output */ - *r = malloc(l * PRF_BLOCKLEN); + *r = calloc(l, PRF_BLOCKLEN); if (!*r) return -1; diff --git a/sbin/raidctl/raidctl.c b/sbin/raidctl/raidctl.c index 2f46e630009..6b2ce6aa782 100644 --- a/sbin/raidctl/raidctl.c +++ b/sbin/raidctl/raidctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raidctl.c,v 1.27 2007/02/21 16:33:09 jmc Exp $ */ +/* $OpenBSD: raidctl.c,v 1.28 2007/09/02 15:19:24 deraadt Exp $ */ /* $NetBSD: raidctl.c,v 1.27 2001/07/10 01:30:52 lukem Exp $ */ /*- @@ -1159,7 +1159,7 @@ open_device(fdidpair **devfd, char *name) } } - if ((*devfd = malloc(nfd * sizeof(fdidpair))) == NULL) + if ((*devfd = calloc(nfd, sizeof(fdidpair))) == NULL) errx(1, "malloc() error"); i = nfd; @@ -1205,7 +1205,7 @@ get_all_devices(char ***diskarray, const char *genericname) fp++; } - *diskarray = (char**) malloc(numdevs * sizeof(void*)); + *diskarray = (char**) calloc(numdevs, sizeof(void*)); i = 0; fp = disks; while ((p = strsep(&fp, ",")) != NULL) { diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c index 69624bfcda6..860de17dab2 100644 --- a/sbin/restore/interactive.c +++ b/sbin/restore/interactive.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interactive.c,v 1.23 2005/06/16 14:51:21 millert Exp $ */ +/* $OpenBSD: interactive.c,v 1.24 2007/09/02 15:19:25 deraadt Exp $ */ /* $NetBSD: interactive.c,v 1.10 1997/03/19 08:42:52 lukem Exp $ */ /* @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)interactive.c 8.3 (Berkeley) 9/13/94"; #else -static const char rcsid[] = "$OpenBSD: interactive.c,v 1.23 2005/06/16 14:51:21 millert Exp $"; +static const char rcsid[] = "$OpenBSD: interactive.c,v 1.24 2007/09/02 15:19:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -535,7 +535,7 @@ printlist(char *name, char *basename) while ((dp = rst_readdir(dirp))) entries++; rst_closedir(dirp); - list = (struct afile *)malloc(entries * sizeof(struct afile)); + list = (struct afile *)calloc(entries, sizeof(struct afile)); if (list == NULL) { fprintf(stderr, "ls: out of memory\n"); return; diff --git a/sbin/restore/main.c b/sbin/restore/main.c index 14c66079b06..d9c26573e78 100644 --- a/sbin/restore/main.c +++ b/sbin/restore/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.17 2007/02/25 16:41:42 jmc Exp $ */ +/* $OpenBSD: main.c,v 1.18 2007/09/02 15:19:25 deraadt Exp $ */ /* $NetBSD: main.c,v 1.13 1997/07/01 05:37:51 lukem Exp $ */ /* @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 9/13/94"; #else -static const char rcsid[] = "$OpenBSD: main.c,v 1.17 2007/02/25 16:41:42 jmc Exp $"; +static const char rcsid[] = "$OpenBSD: main.c,v 1.18 2007/09/02 15:19:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -312,7 +312,7 @@ obsolete(int *argcp, char **argvp[]) return; /* Allocate space for new arguments. */ - if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL || + if ((*argvp = nargv = calloc(argc + 1, sizeof(char *))) == NULL || (p = flagsp = malloc(strlen(ap) + 2)) == NULL) err(1, NULL); diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 0ea205899bc..0120d703290 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tape.c,v 1.32 2007/06/03 20:16:08 millert Exp $ */ +/* $OpenBSD: tape.c,v 1.33 2007/09/02 15:19:25 deraadt Exp $ */ /* $NetBSD: tape.c,v 1.26 1997/04/15 07:12:25 lukem Exp $ */ /* @@ -39,7 +39,7 @@ #if 0 static char sccsid[] = "@(#)tape.c 8.6 (Berkeley) 9/13/94"; #else -static const char rcsid[] = "$OpenBSD: tape.c,v 1.32 2007/06/03 20:16:08 millert Exp $"; +static const char rcsid[] = "$OpenBSD: tape.c,v 1.33 2007/09/02 15:19:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -183,7 +183,7 @@ newtapebuf(long size) return; if (tapebuf != NULL) free(tapebuf); - tapebuf = malloc(size * TP_BSIZE); + tapebuf = calloc(size, TP_BSIZE); if (tapebuf == NULL) errx(1, "Cannot allocate space for tape buffer"); tapebufsize = size; diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index d69bb9b1cbc..9e8b8bef803 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -1,4 +1,4 @@ -/* $OpenBSD: umount.c,v 1.18 2007/01/28 16:23:58 bluhm Exp $ */ +/* $OpenBSD: umount.c,v 1.19 2007/09/02 15:19:25 deraadt Exp $ */ /* $NetBSD: umount.c,v 1.16 1996/05/11 14:13:55 mycroft Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)umount.c 8.3 (Berkeley) 2/20/94"; #else -static char rcsid[] = "$OpenBSD: umount.c,v 1.18 2007/01/28 16:23:58 bluhm Exp $"; +static char rcsid[] = "$OpenBSD: umount.c,v 1.19 2007/09/02 15:19:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -335,7 +335,7 @@ maketypelist(char *fslist) ++nextcp; /* Build an array of that many types. */ - if ((av = typelist = malloc((i + 1) * sizeof(char *))) == NULL) + if ((av = typelist = calloc(i + 1, sizeof(char *))) == NULL) err(1, NULL); av[0] = fslist; for (i = 1, nextcp = fslist; (nextcp = strchr(nextcp, ',')); i++) { diff --git a/usr.bin/asn1_compile/gen_copy.c b/usr.bin/asn1_compile/gen_copy.c index bd311addac5..3341822f81a 100644 --- a/usr.bin/asn1_compile/gen_copy.c +++ b/usr.bin/asn1_compile/gen_copy.c @@ -108,7 +108,7 @@ copy_type (const char *from, const char *to, const Type *t) char *T; fprintf (codefile, "if(((%s)->val = " - "malloc((%s)->len * sizeof(*(%s)->val))) == NULL && (%s)->len != 0)\n", + "calloc((%s)->len, sizeof(*(%s)->val))) == NULL && (%s)->len != 0)\n", to, from, to, from); fprintf (codefile, "return ENOMEM;\n"); fprintf(codefile, diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c index b256401a81e..2b96877bcd7 100644 --- a/usr.bin/at/at.c +++ b/usr.bin/at/at.c @@ -1,4 +1,4 @@ -/* $OpenBSD: at.c,v 1.52 2007/06/18 11:20:58 millert Exp $ */ +/* $OpenBSD: at.c,v 1.53 2007/09/02 15:19:31 deraadt Exp $ */ /* * at.c : Put file into atrun queue @@ -42,7 +42,7 @@ #define TIMESIZE 50 /* Size of buffer passed to strftime() */ #ifndef lint -static const char rcsid[] = "$OpenBSD: at.c,v 1.52 2007/06/18 11:20:58 millert Exp $"; +static const char rcsid[] = "$OpenBSD: at.c,v 1.53 2007/09/02 15:19:31 deraadt Exp $"; #endif /* Variables to remove from the job's environment. */ @@ -489,7 +489,7 @@ list_jobs(int argc, char **argv, int count_only, int csort) int i, shortformat, numjobs, maxjobs; if (argc) { - if ((uids = malloc(sizeof(uid_t) * argc)) == NULL) + if ((uids = calloc(sizeof(uid_t), argc)) == NULL) panic("Insufficient virtual memory"); for (i = 0; i < argc; i++) { @@ -524,7 +524,7 @@ list_jobs(int argc, char **argv, int count_only, int csort) */ numjobs = 0; maxjobs = stbuf.st_nlink + 4; - atjobs = (struct atjob **)malloc(maxjobs * sizeof(struct atjob *)); + atjobs = (struct atjob **)calloc(maxjobs, sizeof(struct atjob *)); if (atjobs == NULL) panic("Insufficient virtual memory"); @@ -663,8 +663,8 @@ process_jobs(int argc, char **argv, int what) uids = NULL; jobs_len = uids_len = 0; if (argc > 0) { - if ((jobs = malloc(sizeof(char *) * argc)) == NULL || - (uids = malloc(sizeof(uid_t) * argc)) == NULL) + if ((jobs = calloc(sizeof(char *), argc)) == NULL || + (uids = calloc(sizeof(uid_t), argc)) == NULL) panic("Insufficient virtual memory"); for (i = 0; i < argc; i++) { diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 1cabd9f017e..9c1e96f166b 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.13 2006/03/19 18:17:11 pvalchev Exp $ */ +/* $OpenBSD: b.c,v 1.14 2007/09/02 15:19:31 deraadt Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -84,8 +84,8 @@ fa *makedfa(const char *s, int anchor) /* returns dfa for reg expr s */ if (setvec == 0) { /* first time through any RE */ maxsetvec = MAXLIN; - setvec = (int *) malloc(maxsetvec * sizeof(int)); - tmpset = (int *) malloc(maxsetvec * sizeof(int)); + setvec = (int *) calloc(maxsetvec, sizeof(int)); + tmpset = (int *) calloc(maxsetvec, sizeof(int)); if (setvec == 0 || tmpset == 0) overflo("out of space initializing makedfa"); } diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index a9204a1ee01..4ec822f7c6d 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.16 2005/11/23 02:43:45 millert Exp $ */ +/* $OpenBSD: lib.c,v 1.17 2007/09/02 15:19:31 deraadt Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -61,7 +61,7 @@ void recinit(unsigned int n) { record = (char *) malloc(n); fields = (char *) malloc(n); - fldtab = (Cell **) malloc((nfields+1) * sizeof(Cell *)); + fldtab = (Cell **) calloc((nfields+1), sizeof(Cell *)); if (record == NULL || fields == NULL || fldtab == NULL) FATAL("out of space for $0 and fields"); diff --git a/usr.bin/bdes/bdes.c b/usr.bin/bdes/bdes.c index fdbb422f8bc..768fc508a15 100644 --- a/usr.bin/bdes/bdes.c +++ b/usr.bin/bdes/bdes.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bdes.c,v 1.14 2004/05/16 18:49:12 otto Exp $ */ +/* $OpenBSD: bdes.c,v 1.15 2007/09/02 15:19:31 deraadt Exp $ */ /* $NetBSD: bdes.c,v 1.2 1995/03/26 03:33:19 glass Exp $ */ /*- @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)bdes.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: bdes.c,v 1.14 2004/05/16 18:49:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: bdes.c,v 1.15 2007/09/02 15:19:31 deraadt Exp $"; #endif #endif /* not lint */ @@ -200,7 +200,7 @@ main(int ac, char *av[]) */ argc = ac; ac = 1; - argv = malloc((argc + 1) * sizeof(char *)); + argv = calloc(argc + 1, sizeof(char *)); if (argv == NULL) errx(1, "out of memory"); for (i = 0; i < argc; ++i) { diff --git a/usr.bin/cdio/cddb.c b/usr.bin/cdio/cddb.c index e89a8bd4cb7..129dae4b3d8 100644 --- a/usr.bin/cdio/cddb.c +++ b/usr.bin/cdio/cddb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cddb.c,v 1.12 2007/05/01 01:26:12 jdixon Exp $ */ +/* $OpenBSD: cddb.c,v 1.13 2007/09/02 15:19:31 deraadt Exp $ */ /* * Copyright (c) 2002 Marc Espie. * @@ -329,7 +329,7 @@ cddb(const char *host_port, int n, struct cd_toc_entry *e, char *arg) } } else if (strcmp(line, "200") != 0 || !further_query(cout, type)) goto end; - result = malloc(sizeof(char *) * (n + 1)); + result = calloc(sizeof(char *), n + 1); if (!result) goto end; for (i = 0; i <= n; i++) diff --git a/usr.bin/file/magic.c b/usr.bin/file/magic.c index f2fd3bb179e..6640ed5cad4 100644 --- a/usr.bin/file/magic.c +++ b/usr.bin/file/magic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: magic.c,v 1.3 2007/07/09 16:39:48 dim Exp $ */ +/* $OpenBSD: magic.c,v 1.4 2007/09/02 15:19:32 deraadt Exp $ */ /* * Copyright (c) Christos Zoulas 2003. * All Rights Reserved. @@ -66,7 +66,7 @@ #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$Id: magic.c,v 1.3 2007/07/09 16:39:48 dim Exp $") +FILE_RCSID("@(#)$Id: magic.c,v 1.4 2007/09/02 15:19:32 deraadt Exp $") #endif /* lint */ #ifdef __EMX__ @@ -104,7 +104,8 @@ magic_open(int flags) free(ms); return NULL; } - ms->c.off = malloc((ms->c.len = 10) * sizeof(*ms->c.off)); + ms->c.len = 10; + ms->c.off = calloc(ms->c.len, sizeof(*ms->c.off)); if (ms->c.off == NULL) { free(ms->o.pbuf); free(ms->o.buf); diff --git a/usr.bin/finger/sprint.c b/usr.bin/finger/sprint.c index c7dd9feaaf8..bf6ee98c963 100644 --- a/usr.bin/finger/sprint.c +++ b/usr.bin/finger/sprint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sprint.c,v 1.11 2005/08/23 13:43:53 espie Exp $ */ +/* $OpenBSD: sprint.c,v 1.12 2007/09/02 15:19:32 deraadt Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -34,7 +34,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)sprint.c 5.8 (Berkeley) 12/4/90";*/ -static const char rcsid[] = "$OpenBSD: sprint.c,v 1.11 2005/08/23 13:43:53 espie Exp $"; +static const char rcsid[] = "$OpenBSD: sprint.c,v 1.12 2007/09/02 15:19:32 deraadt Exp $"; #endif /* not lint */ #include @@ -141,7 +141,7 @@ sort(void) PERSON *pn, **lp; PERSON **list; - if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) + if (!(list = (PERSON **)calloc((u_int)entries, sizeof(PERSON *)))) err(1, "malloc"); for (lp = list, pn = phead; pn != NULL; pn = pn->next) *lp++ = pn; diff --git a/usr.bin/fsplit/fsplit.c b/usr.bin/fsplit/fsplit.c index 923dca8621d..86dbb64bb13 100644 --- a/usr.bin/fsplit/fsplit.c +++ b/usr.bin/fsplit/fsplit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsplit.c,v 1.15 2003/06/26 21:42:11 deraadt Exp $ */ +/* $OpenBSD: fsplit.c,v 1.16 2007/09/02 15:19:32 deraadt Exp $ */ /* * Copyright (c) 1983, 1993 @@ -40,7 +40,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)fsplit.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: fsplit.c,v 1.15 2003/06/26 21:42:11 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: fsplit.c,v 1.16 2007/09/02 15:19:32 deraadt Exp $"; #endif /* not lint */ #include @@ -115,7 +115,7 @@ main(int argc, char *argv[]) char name[20]; maxextrknt = 100; - extrnames = malloc(sizeof(char *) * maxextrknt); + extrnames = calloc(sizeof(char *), maxextrknt); if (extrnames == NULL) errx(1, "out of memory"); /* scan -e options */ diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 72fe4fd44ef..473b6f901f8 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fstat.c,v 1.58 2007/04/07 23:20:19 tedu Exp $ */ +/* $OpenBSD: fstat.c,v 1.59 2007/09/02 15:19:32 deraadt Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -37,7 +37,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)fstat.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$OpenBSD: fstat.c,v 1.58 2007/04/07 23:20:19 tedu Exp $"; +static char *rcsid = "$OpenBSD: fstat.c,v 1.59 2007/09/02 15:19:32 deraadt Exp $"; #endif /* not lint */ #include @@ -131,7 +131,7 @@ int maxfiles; #define ALLOC_OFILES(d) \ if ((d) > maxfiles) { \ free(ofiles); \ - ofiles = malloc((d) * sizeof(struct file *)); \ + ofiles = calloc((d), sizeof(struct file *)); \ if (ofiles == NULL) \ err(1, "malloc"); \ maxfiles = (d); \ diff --git a/usr.bin/ftp/stringlist.c b/usr.bin/ftp/stringlist.c index 28bba57c8df..a0823e67af1 100644 --- a/usr.bin/ftp/stringlist.c +++ b/usr.bin/ftp/stringlist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stringlist.c,v 1.7 2006/04/25 05:45:20 tedu Exp $ */ +/* $OpenBSD: stringlist.c,v 1.8 2007/09/02 15:19:32 deraadt Exp $ */ /* $NetBSD: stringlist.c,v 1.2 1997/01/17 07:26:20 lukem Exp $ */ /* @@ -33,7 +33,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) && !defined(SMALL) -static const char rcsid[] = "$OpenBSD: stringlist.c,v 1.7 2006/04/25 05:45:20 tedu Exp $"; +static const char rcsid[] = "$OpenBSD: stringlist.c,v 1.8 2007/09/02 15:19:32 deraadt Exp $"; #endif /* LIBC_SCCS and not lint and not SMALL */ #include @@ -57,7 +57,7 @@ sl_init(void) sl->sl_cur = 0; sl->sl_max = _SL_CHUNKSIZE; - sl->sl_str = malloc(sl->sl_max * sizeof(char *)); + sl->sl_str = calloc(sl->sl_max, sizeof(char *)); if (sl->sl_str == NULL) err(1, "stringlist"); return sl; diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index a8a35e3b702..a78b66b1d51 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.38 2007/02/13 21:48:20 kili Exp $ */ +/* $OpenBSD: grep.c,v 1.39 2007/09/02 15:19:32 deraadt Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -450,8 +450,8 @@ main(int argc, char *argv[]) if (Eflag) cflags |= REG_EXTENDED; - fg_pattern = grep_malloc(patterns * sizeof(*fg_pattern)); - r_pattern = grep_malloc(patterns * sizeof(*r_pattern)); + fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern)); + r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); for (i = 0; i < patterns; ++i) { /* Check if cheating is allowed (always is for fgrep). */ if (Fflag) { diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h index b753bc8740a..5ba9b442347 100644 --- a/usr.bin/grep/grep.h +++ b/usr.bin/grep/grep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.h,v 1.13 2006/02/09 09:54:47 otto Exp $ */ +/* $OpenBSD: grep.h,v 1.14 2007/09/02 15:19:32 deraadt Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -82,6 +82,7 @@ extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */ int procfile(char *fn); int grep_tree(char **argv); void *grep_malloc(size_t size); +void *grep_calloc(size_t nmemb, size_t size); void *grep_realloc(void *ptr, size_t size); void printline(str_t *line, int sep); int fastcomp(fastgrep_t *, const char *); diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c index 0af93493a36..970dd1413e2 100644 --- a/usr.bin/grep/util.c +++ b/usr.bin/grep/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.34 2006/12/26 20:59:23 otto Exp $ */ +/* $OpenBSD: util.c,v 1.35 2007/09/02 15:19:32 deraadt Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -512,6 +512,16 @@ grep_malloc(size_t size) return ptr; } +void * +grep_calloc(size_t nmemb, size_t size) +{ + void *ptr; + + if ((ptr = calloc(nmemb, size)) == NULL) + err(2, "calloc"); + return ptr; +} + void * grep_realloc(void *ptr, size_t size) { diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index e513cf4877f..97f19eb8b96 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lexi.c,v 1.12 2005/03/06 14:34:25 millert Exp $ */ +/* $OpenBSD: lexi.c,v 1.13 2007/09/02 15:19:32 deraadt Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #ifndef lint /*static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";*/ -static char rcsid[] = "$OpenBSD: lexi.c,v 1.12 2005/03/06 14:34:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: lexi.c,v 1.13 2007/09/02 15:19:32 deraadt Exp $"; #endif /* not lint */ /* @@ -579,7 +579,7 @@ addkey(char *key, int val) */ nspecials = sizeof (specialsinit) / sizeof (specialsinit[0]); maxspecials = nspecials + (nspecials >> 2); - specials = (struct templ *)malloc(maxspecials * sizeof specials[0]); + specials = (struct templ *)calloc(maxspecials, sizeof specials[0]); if (specials == NULL) err(1, NULL); memcpy(specials, specialsinit, sizeof specialsinit); diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c index eb96c175404..be8809da98e 100644 --- a/usr.bin/locate/locate/util.c +++ b/usr.bin/locate/locate/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.9 2003/11/08 19:17:29 jmc Exp $ +/* $OpenBSD: util.c,v 1.10 2007/09/02 15:19:33 deraadt Exp $ * * Copyright (c) 1995 Wolfram Schneider . Berlin. * Copyright (c) 1989, 1993 @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: util.c,v 1.9 2003/11/08 19:17:29 jmc Exp $ + * $Id: util.c,v 1.10 2007/09/02 15:19:33 deraadt Exp $ */ @@ -115,7 +115,7 @@ colon(dbv, path, dot) else { /* a string */ slen = ch - c; - if ((p = malloc(sizeof(char) * (slen + 1))) + if ((p = calloc(sizeof(char), slen + 1)) == NULL) err(1, "malloc"); bcopy(c, p, slen); diff --git a/usr.bin/midiplay/midiplay.c b/usr.bin/midiplay/midiplay.c index d6498c62d1e..ba41a7591eb 100644 --- a/usr.bin/midiplay/midiplay.c +++ b/usr.bin/midiplay/midiplay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midiplay.c,v 1.8 2005/11/06 00:56:51 jsg Exp $ */ +/* $OpenBSD: midiplay.c,v 1.9 2007/09/02 15:19:33 deraadt Exp $ */ /* $NetBSD: midiplay.c,v 1.8 1998/11/25 22:17:07 augustss Exp $ */ /* @@ -321,7 +321,7 @@ playdata(u_char *buf, u_int tot, char *name) } if (ntrks == 0) return; - tracks = malloc(ntrks * sizeof(struct track)); + tracks = calloc(ntrks, sizeof(struct track)); if (tracks == NULL) err(1, "malloc() tracks failed"); for (t = 0; t < ntrks; ) { diff --git a/usr.bin/nm/elf.c b/usr.bin/nm/elf.c index 17559bbb44b..8903b7a351b 100644 --- a/usr.bin/nm/elf.c +++ b/usr.bin/nm/elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: elf.c,v 1.17 2007/04/18 19:03:04 miod Exp $ */ +/* $OpenBSD: elf.c,v 1.18 2007/09/02 15:19:33 deraadt Exp $ */ /* * Copyright (c) 2003 Michael Shalayeff @@ -27,7 +27,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: elf.c,v 1.17 2007/04/18 19:03:04 miod Exp $"; +static const char rcsid[] = "$OpenBSD: elf.c,v 1.18 2007/09/02 15:19:33 deraadt Exp $"; #endif /* not lint */ #include @@ -148,7 +148,7 @@ elf_load_shdrs(const char *name, FILE *fp, off_t foff, Elf_Ehdr *head) elf_fix_header(head); - if ((shdr = malloc(head->e_shentsize * head->e_shnum)) == NULL) { + if ((shdr = calloc(head->e_shentsize, head->e_shnum)) == NULL) { warn("%s: malloc shdr", name); return (NULL); } @@ -174,7 +174,7 @@ elf_load_phdrs(const char *name, FILE *fp, off_t foff, Elf_Ehdr *head) { Elf_Phdr *phdr; - if ((phdr = malloc(head->e_phentsize * head->e_phnum)) == NULL) { + if ((phdr = calloc(head->e_phentsize, head->e_phnum)) == NULL) { warn("%s: malloc phdr", name); return (NULL); } @@ -473,7 +473,7 @@ elf_symloadx(const char *name, FILE *fp, off_t foff, Elf_Ehdr *eh, MUNMAP(stab, *pstabsize); return (1); } - if ((*psnames = malloc(*pnrawnames * sizeof(np))) == NULL) { + if ((*psnames = calloc(*pnrawnames, sizeof(np))) == NULL) { warn("%s: malloc snames", name); if (stab) MUNMAP(stab, *pstabsize); diff --git a/usr.bin/nm/nm.c b/usr.bin/nm/nm.c index daf2cfb3715..bb53c435486 100644 --- a/usr.bin/nm/nm.c +++ b/usr.bin/nm/nm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nm.c,v 1.30 2007/08/06 19:16:06 sobrado Exp $ */ +/* $OpenBSD: nm.c,v 1.31 2007/09/02 15:19:33 deraadt Exp $ */ /* $NetBSD: nm.c,v 1.7 1996/01/14 23:04:03 pk Exp $ */ /* @@ -42,7 +42,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)nm.c 8.1 (Berkeley) 6/6/93"; #endif -static const char rcsid[] = "$OpenBSD: nm.c,v 1.30 2007/08/06 19:16:06 sobrado Exp $"; +static const char rcsid[] = "$OpenBSD: nm.c,v 1.31 2007/09/02 15:19:33 deraadt Exp $"; #include #include @@ -692,12 +692,12 @@ show_file(int count, int warn_fmt, const char *name, FILE *fp, off_t foff, union nrawnames = head->aout.a_syms / sizeof(*names); #endif /* get memory for the symbol table */ - if ((names = malloc(nrawnames * sizeof(struct nlist))) == NULL) { + if ((names = calloc(nrawnames, sizeof(struct nlist))) == NULL) { warn("%s: malloc names", name); return (1); } - if ((snames = malloc(nrawnames * sizeof(struct nlist *))) == NULL) { + if ((snames = calloc(nrawnames, sizeof(struct nlist *))) == NULL) { warn("%s: malloc snames", name); free(names); return (1); diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index e41ddf8c757..c2d1eeab021 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pch.c,v 1.36 2006/03/11 19:41:30 otto Exp $ */ +/* $OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $ */ /* * patch - a program to apply diffs to original files @@ -27,7 +27,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: pch.c,v 1.36 2006/03/11 19:41:30 otto Exp $"; +static const char rcsid[] = "$OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $"; #endif /* not lint */ #include @@ -129,11 +129,11 @@ void set_hunkmax(void) { if (p_line == NULL) - p_line = malloc((size_t) hunkmax * sizeof(char *)); + p_line = calloc((size_t) hunkmax, sizeof(char *)); if (p_len == NULL) - p_len = malloc((size_t) hunkmax * sizeof(short)); + p_len = calloc((size_t) hunkmax, sizeof(short)); if (p_char == NULL) - p_char = malloc((size_t) hunkmax * sizeof(char)); + p_char = calloc((size_t) hunkmax, sizeof(char)); } /* diff --git a/usr.bin/pmdb/clit.c b/usr.bin/pmdb/clit.c index 249710f5d12..bef9bf28d62 100644 --- a/usr.bin/pmdb/clit.c +++ b/usr.bin/pmdb/clit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clit.c,v 1.5 2003/10/31 08:47:31 otto Exp $ */ +/* $OpenBSD: clit.c,v 1.6 2007/09/02 15:19:33 deraadt Exp $ */ /* * Copyright (c) 2002 Artur Grabowski * All rights reserved. @@ -186,7 +186,7 @@ cmdloop(void *arg) stop = 0; - if ((argv = malloc(sizeof(char *) * maxargs)) == NULL) + if ((argv = calloc(sizeof(char *), maxargs)) == NULL) err(1, "malloc"); while (!stop && (elline = el_gets(el, &cnt)) != NULL) { diff --git a/usr.bin/rs/rs.c b/usr.bin/rs/rs.c index f3524bc0624..bd0fffc33c1 100644 --- a/usr.bin/rs/rs.c +++ b/usr.bin/rs/rs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rs.c,v 1.17 2006/04/17 09:45:00 moritz Exp $ */ +/* $OpenBSD: rs.c,v 1.18 2007/09/02 15:19:34 deraadt Exp $ */ /*- * Copyright (c) 1993 @@ -39,7 +39,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)rs.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: rs.c,v 1.17 2006/04/17 09:45:00 moritz Exp $"; +static const char rcsid[] = "$OpenBSD: rs.c,v 1.18 2007/09/02 15:19:34 deraadt Exp $"; #endif #endif /* not lint */ @@ -281,7 +281,7 @@ prepfile(void) *ep = *(ep - nelem); nelem = lp - elem; } - if (!(colwidths = (short *) malloc(ocols * sizeof(short)))) + if (!(colwidths = (short *) calloc(ocols, sizeof(short)))) errx(1, "malloc: No gutter space"); if (flags & SQUEEZE) { if (flags & TRANSPOSE) diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c index a6d9a352c89..60e4609977f 100644 --- a/usr.bin/rusers/rusers.c +++ b/usr.bin/rusers/rusers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rusers.c,v 1.28 2007/05/25 21:27:16 krw Exp $ */ +/* $OpenBSD: rusers.c,v 1.29 2007/09/02 15:19:34 deraadt Exp $ */ /* * Copyright (c) 2001, 2003 Todd C. Miller @@ -47,7 +47,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: rusers.c,v 1.28 2007/05/25 21:27:16 krw Exp $"; +static const char rcsid[] = "$OpenBSD: rusers.c,v 1.29 2007/09/02 15:19:34 deraadt Exp $"; #endif /* not lint */ #include @@ -260,7 +260,7 @@ rusers_reply(char *replyp, struct sockaddr_in *raddrp) if (up->uia_cnt == 0) ut = NULL; - else if ((ut = malloc(up->uia_cnt * sizeof(*ut))) == NULL) + else if ((ut = calloc(up->uia_cnt, sizeof(*ut))) == NULL) err(1, NULL); entry->users = ut; entry->count = up->uia_cnt; @@ -315,7 +315,7 @@ rusers_reply_3(char *replyp, struct sockaddr_in *raddrp) if (up3->utmp_array_len == 0) ut = NULL; - else if ((ut = malloc(up3->utmp_array_len * sizeof(*ut))) == NULL) + else if ((ut = calloc(up3->utmp_array_len, sizeof(*ut))) == NULL) err(1, NULL); entry->users = ut; entry->count = up3->utmp_array_len; @@ -689,7 +689,7 @@ expandhosts(void) for (i = 0, count = 0; i < nentries; i++) count += hostinfo[i].count; - new_hostinfo = (struct host_info *)malloc(sizeof(*entry) * count); + new_hostinfo = (struct host_info *)calloc(sizeof(*entry), count); if (new_hostinfo == NULL) err(1, NULL); for (i = 0, entry = new_hostinfo; i < nentries; i++) { diff --git a/usr.bin/sdiff/sdiff.c b/usr.bin/sdiff/sdiff.c index 9e679d435bc..98d78c2bd5a 100644 --- a/usr.bin/sdiff/sdiff.c +++ b/usr.bin/sdiff/sdiff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdiff.c,v 1.22 2007/06/28 02:14:41 ray Exp $ */ +/* $OpenBSD: sdiff.c,v 1.23 2007/09/02 15:19:34 deraadt Exp $ */ /* * Written by Raymond Lai . @@ -172,7 +172,7 @@ main(int argc, char **argv) * waste some memory; however we need an extra space for the * NULL at the end, so it sort of works out. */ - if (!(diffargv = malloc(sizeof(char **) * argc * 2))) + if (!(diffargv = calloc(argc, sizeof(char **) * 2))) err(2, "main"); /* Add first argument, the program name. */ diff --git a/usr.bin/spell/spellprog.c b/usr.bin/spell/spellprog.c index 70aa381f9fb..5528cce8cdf 100644 --- a/usr.bin/spell/spellprog.c +++ b/usr.bin/spell/spellprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spellprog.c,v 1.4 2003/06/03 02:56:16 millert Exp $ */ +/* $OpenBSD: spellprog.c,v 1.5 2007/09/02 15:19:34 deraadt Exp $ */ /* * Copyright (c) 1991, 1993 @@ -75,7 +75,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)spell.c 8.1 (Berkeley) 6/6/93"; #else #endif -static const char rcsid[] = "$OpenBSD: spellprog.c,v 1.4 2003/06/03 02:56:16 millert Exp $"; +static const char rcsid[] = "$OpenBSD: spellprog.c,v 1.5 2007/09/02 15:19:34 deraadt Exp $"; #endif /* not lint */ #include @@ -292,7 +292,7 @@ main(int argc, char **argv) usage(); /* Open and mmap the word/stop lists. */ - if ((wlists = malloc(sizeof(struct wlist) * (argc + 1))) == NULL) + if ((wlists = calloc(sizeof(struct wlist), (argc + 1))) == NULL) err(1, "malloc"); for (i = 0; argc--; i++) { wlists[i].fd = open(argv[i], O_RDONLY, 0); diff --git a/usr.bin/strip/strip.c b/usr.bin/strip/strip.c index ca19fc80eb8..506d0c5c4ae 100644 --- a/usr.bin/strip/strip.c +++ b/usr.bin/strip/strip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strip.c,v 1.23 2004/10/09 20:36:05 mickey Exp $ */ +/* $OpenBSD: strip.c,v 1.24 2007/09/02 15:19:34 deraadt Exp $ */ /* * Copyright (c) 1988 Regents of the University of California. @@ -37,7 +37,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)strip.c 5.8 (Berkeley) 11/6/91";*/ -static char rcsid[] = "$OpenBSD: strip.c,v 1.23 2004/10/09 20:36:05 mickey Exp $"; +static char rcsid[] = "$OpenBSD: strip.c,v 1.24 2007/09/02 15:19:34 deraadt Exp $"; #endif /* not lint */ #include @@ -268,7 +268,7 @@ s_stab(const char *fn, int fd, EXEC *ep, struct stat *sp, off_t *sz) warnx("%s", strerror(ENOMEM)); goto end; } - mapping = malloc(nsyms * sizeof(unsigned int)); + mapping = calloc(nsyms, sizeof(unsigned int)); if (!mapping) { warnx("%s", strerror(ENOMEM)); goto end; diff --git a/usr.bin/sudo/parse.yacc b/usr.bin/sudo/parse.yacc index a759212640d..f5fdb02fd67 100644 --- a/usr.bin/sudo/parse.yacc +++ b/usr.bin/sudo/parse.yacc @@ -1019,7 +1019,7 @@ more_aliases() nslots += MOREALIASES; if (nslots == MOREALIASES) - aliases = (aliasinfo *) malloc(nslots * sizeof(aliasinfo)); + aliases = (aliasinfo *) calloc(nslots, sizeof(aliasinfo)); else aliases = (aliasinfo *) realloc(aliases, nslots * sizeof(aliasinfo)); diff --git a/usr.bin/sup/src/scm.c b/usr.bin/sup/src/scm.c index f6fad5cade4..7093440863a 100644 --- a/usr.bin/sup/src/scm.c +++ b/usr.bin/sup/src/scm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scm.c,v 1.18 2005/03/10 01:36:37 cloder Exp $ */ +/* $OpenBSD: scm.c,v 1.19 2007/09/02 15:19:35 deraadt Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -576,7 +576,7 @@ samehost() /* is remote host same as local host? */ if ((nint = ifc.ifc_len / sizeof(struct ifreq)) <= 0) return (0); intp = (struct in_addr *) - malloc (nint * sizeof(struct in_addr)); + calloc (nint, sizeof(struct in_addr)); if ((ifp = intp) == 0) logquit (1, "no space for interfaces"); for (ifr = ifc.ifc_req, n = nint; n > 0; --n, ifr++) { diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c index 2f2640e8112..46b36311559 100644 --- a/usr.bin/systat/pigs.c +++ b/usr.bin/systat/pigs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pigs.c,v 1.20 2007/02/25 18:21:24 deraadt Exp $ */ +/* $OpenBSD: pigs.c,v 1.21 2007/09/02 15:19:35 deraadt Exp $ */ /* $NetBSD: pigs.c,v 1.3 1995/04/29 05:54:50 cgd Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93"; #endif -static char rcsid[] = "$OpenBSD: pigs.c,v 1.20 2007/02/25 18:21:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: pigs.c,v 1.21 2007/09/02 15:19:35 deraadt Exp $"; #endif /* not lint */ /* @@ -181,8 +181,7 @@ fetchpigs(void) } if (nproc > lastnproc) { free(pt); - if ((pt = - malloc((nproc + 1) * sizeof(struct p_times))) == NULL) { + if ((pt = calloc(nproc + 1, sizeof(struct p_times))) == NULL) { error("Out of memory"); die(); } diff --git a/usr.bin/vi/cl/cl_read.c b/usr.bin/vi/cl/cl_read.c index b2070f3c292..315806019ac 100644 --- a/usr.bin/vi/cl/cl_read.c +++ b/usr.bin/vi/cl/cl_read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_read.c,v 1.14 2007/07/26 16:11:56 millert Exp $ */ +/* $OpenBSD: cl_read.c,v 1.15 2007/09/02 15:19:35 deraadt Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -159,7 +159,7 @@ cl_read(sp, flags, bp, blen, nrp, tp) CIRCLEQ_FOREACH(tsp, &gp->dq, q) if (F_ISSET(tsp, SC_SCRIPT) && tsp->script->sh_master > maxfd) maxfd = tsp->script->sh_master; - rdfd = (fd_set *)malloc(howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); + rdfd = (fd_set *)calloc(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); if (rdfd == NULL) goto err; diff --git a/usr.bin/vi/ex/ex_script.c b/usr.bin/vi/ex/ex_script.c index bb6bf982cd4..7852b7b7344 100644 --- a/usr.bin/vi/ex/ex_script.c +++ b/usr.bin/vi/ex/ex_script.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_script.c,v 1.13 2006/01/08 21:05:40 miod Exp $ */ +/* $OpenBSD: ex_script.c,v 1.14 2007/09/02 15:19:35 deraadt Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -388,7 +388,7 @@ sscr_input(sp) CIRCLEQ_FOREACH(sp, &gp->dq, q) if (F_ISSET(sp, SC_SCRIPT) && sp->script->sh_master > maxfd) maxfd = sp->script->sh_master; - rdfd = (fd_set *)malloc(howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask)); + rdfd = (fd_set *)calloc(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask)); if (rdfd == NULL) { msgq(sp, M_SYSERR, "malloc"); return (1); diff --git a/usr.bin/window/compress.c b/usr.bin/window/compress.c index 059909bf107..776e1bc4ffa 100644 --- a/usr.bin/window/compress.c +++ b/usr.bin/window/compress.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compress.c,v 1.7 2003/07/10 00:06:52 david Exp $ */ +/* $OpenBSD: compress.c,v 1.8 2007/09/02 15:19:35 deraadt Exp $ */ /* $NetBSD: compress.c,v 1.3 1995/09/28 10:34:13 tls Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)compress.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: compress.c,v 1.7 2003/07/10 00:06:52 david Exp $"; +static char rcsid[] = "$OpenBSD: compress.c,v 1.8 2007/09/02 15:19:35 deraadt Exp $"; #endif #endif /* not lint */ @@ -238,29 +238,29 @@ ccinit() #endif #undef C if ((cc_output = (struct cc **) - malloc(cc_bufsize * sizeof *cc_output)) == 0) + calloc(cc_bufsize, sizeof *cc_output)) == 0) goto nomem; if ((cc_hashcodes = (short *) - malloc(cc_bufsize * sizeof *cc_hashcodes)) == 0) + calloc(cc_bufsize, sizeof *cc_hashcodes)) == 0) goto nomem; - if ((cc_htab = (struct cc **) malloc(HSIZE * sizeof *cc_htab)) == 0) + if ((cc_htab = (struct cc **) calloc(HSIZE, sizeof *cc_htab)) == 0) goto nomem; if ((cc_tokens = (struct cc **) - malloc((cc_ntoken + tt.tt_token_max - tt.tt_token_min + 1) * - sizeof *cc_tokens)) == 0) + malloc(cc_ntoken + tt.tt_token_max - tt.tt_token_min + 1), + sizeof *cc_tokens) == 0) goto nomem; if ((cc_undo = (struct cc_undo *) - malloc(cc_bufsize * sizeof *cc_undo)) == 0) + calloc(cc_bufsize, sizeof *cc_undo)) == 0) goto nomem; for (i = tt.tt_token_min; i <= tt.tt_token_max; i++) if ((cc_places[i] = (short *) - malloc(cc_bufsize * sizeof **cc_places)) == 0) + calloc(cc_bufsize, sizeof **cc_places)) == 0) goto nomem; cc_q0a.qforw = cc_q0a.qback = &cc_q0a; cc_q0b.qforw = cc_q0b.qback = &cc_q0b; cc_q1a.qforw = cc_q1a.qback = &cc_q1a; cc_q1b.qforw = cc_q1b.qback = &cc_q1b; - if ((p = (struct cc *) malloc(cc_ntoken * sizeof *p)) == 0) + if ((p = (struct cc *) calloc(cc_ntoken, sizeof *p)) == 0) goto nomem; for (i = 0; i < tt.tt_ntoken; i++) { p->code = i; diff --git a/usr.bin/window/wwinit.c b/usr.bin/window/wwinit.c index aee8ea603df..81407abebbd 100644 --- a/usr.bin/window/wwinit.c +++ b/usr.bin/window/wwinit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wwinit.c,v 1.17 2006/01/02 16:20:56 millert Exp $ */ +/* $OpenBSD: wwinit.c,v 1.18 2007/09/02 15:19:35 deraadt Exp $ */ /* $NetBSD: wwinit.c,v 1.11 1996/02/08 21:49:07 mycroft Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)wwinit.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: wwinit.c,v 1.17 2006/01/02 16:20:56 millert Exp $"; +static char rcsid[] = "$OpenBSD: wwinit.c,v 1.18 2007/09/02 15:19:35 deraadt Exp $"; #endif #endif /* not lint */ @@ -265,7 +265,7 @@ wwinit() for (i = 0; i < wwnrow; i++) wwtouched[i] = 0; - wwupd = (struct ww_update *) malloc(wwnrow * sizeof *wwupd); + wwupd = (struct ww_update *) calloc(wwnrow, sizeof *wwupd); if (wwupd == 0) { wwerrno = WWE_NOMEM; goto bad; diff --git a/usr.bin/window/wwopen.c b/usr.bin/window/wwopen.c index 804da4a96c0..c10f39191b9 100644 --- a/usr.bin/window/wwopen.c +++ b/usr.bin/window/wwopen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wwopen.c,v 1.10 2003/07/10 00:06:52 david Exp $ */ +/* $OpenBSD: wwopen.c,v 1.11 2007/09/02 15:19:35 deraadt Exp $ */ /* $NetBSD: wwopen.c,v 1.6 1996/02/08 21:08:04 mycroft Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)wwopen.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$OpenBSD: wwopen.c,v 1.10 2003/07/10 00:06:52 david Exp $"; +static char rcsid[] = "$OpenBSD: wwopen.c,v 1.11 2007/09/02 15:19:35 deraadt Exp $"; #endif #endif /* not lint */ @@ -165,7 +165,7 @@ wwopen(type, oflags, nrow, ncol, row, col, nline) for (j = w->ww_b.l; j < w->ww_b.r; j++) w->ww_buf[i][j].c_w = ' '; - w->ww_nvis = (short *)malloc(w->ww_w.nr * sizeof (short)); + w->ww_nvis = (short *)calloc(w->ww_w.nr, sizeof (short)); if (w->ww_nvis == 0) { wwerrno = WWE_NOMEM; goto bad; diff --git a/usr.bin/window/wwsize.c b/usr.bin/window/wwsize.c index 9d51ce82aba..3fa81533825 100644 --- a/usr.bin/window/wwsize.c +++ b/usr.bin/window/wwsize.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wwsize.c,v 1.8 2003/06/03 02:56:23 millert Exp $ */ +/* $OpenBSD: wwsize.c,v 1.9 2007/09/02 15:19:36 deraadt Exp $ */ /* $NetBSD: wwsize.c,v 1.5 1996/02/08 20:45:11 mycroft Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)wwsize.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: wwsize.c,v 1.8 2003/06/03 02:56:23 millert Exp $"; +static char rcsid[] = "$OpenBSD: wwsize.c,v 1.9 2007/09/02 15:19:36 deraadt Exp $"; #endif #endif /* not lint */ @@ -76,7 +76,7 @@ struct ww *w; if (buf == 0) goto bad; } - nvis = (short *)malloc(nrow * sizeof (short)); + nvis = (short *)calloc(nrow, sizeof (short)); if (nvis == 0) { wwerrno = WWE_NOMEM; goto bad; diff --git a/usr.bin/window/xx.c b/usr.bin/window/xx.c index c6037991772..96288d0c055 100644 --- a/usr.bin/window/xx.c +++ b/usr.bin/window/xx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xx.c,v 1.7 2003/07/18 23:11:43 david Exp $ */ +/* $OpenBSD: xx.c,v 1.8 2007/09/02 15:19:36 deraadt Exp $ */ /* $NetBSD: xx.c,v 1.3 1995/09/28 10:36:03 tls Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)xx.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: xx.c,v 1.7 2003/07/18 23:11:43 david Exp $"; +static char rcsid[] = "$OpenBSD: xx.c,v 1.8 2007/09/02 15:19:36 deraadt Exp $"; #endif #endif /* not lint */ @@ -55,7 +55,7 @@ xxinit() /* ccinit may choose to change xxbufsize */ if (tt.tt_ntoken > 0 && ccinit() < 0) return -1; - xxbuf = malloc(xxbufsize * sizeof *xxbuf); + xxbuf = calloc(xxbufsize, sizeof *xxbuf); if (xxbuf == 0) { wwerrno = WWE_NOMEM; return -1; diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 77c74df28d4..b63733afc98 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xargs.c,v 1.24 2005/11/01 04:52:59 deraadt Exp $ */ +/* $OpenBSD: xargs.c,v 1.25 2007/09/02 15:19:36 deraadt Exp $ */ /* $FreeBSD: xargs.c,v 1.51 2003/05/03 19:09:11 obrien Exp $ */ /*- @@ -45,7 +45,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: xargs.c,v 1.24 2005/11/01 04:52:59 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: xargs.c,v 1.25 2007/09/02 15:19:36 deraadt Exp $"; #endif #endif /* not lint */ @@ -200,7 +200,7 @@ main(int argc, char *argv[]) * NULL. */ linelen = 1 + argc + nargs + 1; - if ((av = bxp = malloc(linelen * sizeof(char **))) == NULL) + if ((av = bxp = calloc(linelen, sizeof(char **))) == NULL) err(1, NULL); /* @@ -423,7 +423,7 @@ prerun(int argc, char *argv[]) * Allocate memory to hold the argument list, and * a NULL at the tail. */ - tmp = malloc((argc + 1) * sizeof(char**)); + tmp = calloc(argc + 1, sizeof(char**)); if (tmp == NULL) err(1, NULL); tmp2 = tmp; diff --git a/usr.bin/yacc/skeleton.c b/usr.bin/yacc/skeleton.c index 1df001637b0..09e43768924 100644 --- a/usr.bin/yacc/skeleton.c +++ b/usr.bin/yacc/skeleton.c @@ -1,4 +1,4 @@ -/* $OpenBSD: skeleton.c,v 1.26 2006/04/20 16:51:32 deraadt Exp $ */ +/* $OpenBSD: skeleton.c,v 1.27 2007/09/02 15:19:36 deraadt Exp $ */ /* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */ /* @@ -63,7 +63,7 @@ char *banner[] = "#if __GNUC__ >= 2", " __attribute__ ((unused))", "#endif /* __GNUC__ >= 2 */", - " = \"$OpenBSD: skeleton.c,v 1.26 2006/04/20 16:51:32 deraadt Exp $\";", + " = \"$OpenBSD: skeleton.c,v 1.27 2007/09/02 15:19:36 deraadt Exp $\";", "#endif", "#include ", "#define YYBYACC 1", @@ -165,13 +165,13 @@ char *body[] = " newsize = YYMAXDEPTH;", " i = yyssp - yyss;", " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :", - " (short *)malloc(newsize * sizeof *newss);", + " (short *)calloc(newsize, sizeof *newss);", " if (newss == NULL)", " goto bail;", " yyss = newss;", " yyssp = newss + i;", " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :", - " (YYSTYPE *)malloc(newsize * sizeof *newvs);", + " (YYSTYPE *)calloc(newsize, sizeof *newvs);", " if (newvs == NULL)", " goto bail;", " yyvs = newvs;", diff --git a/usr.sbin/cron/env.c b/usr.sbin/cron/env.c index aacce1d9ccc..018f2841f46 100644 --- a/usr.sbin/cron/env.c +++ b/usr.sbin/cron/env.c @@ -1,4 +1,4 @@ -/* $OpenBSD: env.c,v 1.18 2005/01/30 20:44:50 millert Exp $ */ +/* $OpenBSD: env.c,v 1.19 2007/09/02 15:19:38 deraadt Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: env.c,v 1.18 2005/01/30 20:44:50 millert Exp $"; +static char const rcsid[] = "$OpenBSD: env.c,v 1.19 2007/09/02 15:19:38 deraadt Exp $"; #endif #include "cron.h" @@ -52,7 +52,7 @@ env_copy(char **envp) { for (count = 0; envp[count] != NULL; count++) continue; - p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */ + p = (char **) calloc(count+1, sizeof(char *)); /* 1 for the NULL */ if (p != NULL) { for (i = 0; i < count; i++) if ((p[i] = strdup(envp[i])) == NULL) { diff --git a/usr.sbin/dhcrelay/dispatch.c b/usr.sbin/dhcrelay/dispatch.c index 81b66e70ce0..cf027ab2d04 100644 --- a/usr.sbin/dhcrelay/dispatch.c +++ b/usr.sbin/dhcrelay/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.6 2006/12/18 01:08:58 stevesk Exp $ */ +/* $OpenBSD: dispatch.c,v 1.7 2007/09/02 15:19:38 deraadt Exp $ */ /* * Copyright 2004 Henning Brauer @@ -146,7 +146,7 @@ dispatch(void) for (l = protocols; l; l = l->next) nfds++; - fds = malloc(nfds * sizeof(struct pollfd)); + fds = calloc(nfds, sizeof(struct pollfd)); if (fds == NULL) error("Can't allocate poll structures."); diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c index 04bf9c0716c..d29339f8a8c 100644 --- a/usr.sbin/kvm_mkdb/nlist.c +++ b/usr.sbin/kvm_mkdb/nlist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nlist.c,v 1.36 2007/03/18 16:28:10 mickey Exp $ */ +/* $OpenBSD: nlist.c,v 1.37 2007/09/02 15:19:38 deraadt Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -33,7 +33,7 @@ #if 0 static char sccsid[] = "from: @(#)nlist.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: nlist.c,v 1.36 2007/03/18 16:28:10 mickey Exp $"; +static const char rcsid[] = "$OpenBSD: nlist.c,v 1.37 2007/09/02 15:19:38 deraadt Exp $"; #endif #endif /* not lint */ @@ -317,7 +317,7 @@ __elf_knlist(int fd, DB *db, int ksyms) !IS_ELF(eh)) return (1); - sh = (Elf_Shdr *)malloc(sizeof(Elf_Shdr) * eh.e_shnum); + sh = (Elf_Shdr *)calloc(sizeof(Elf_Shdr), eh.e_shnum); if (sh == NULL) errx(1, "cannot allocate %d bytes for symbol header", sizeof(Elf_Shdr) * eh.e_shnum); diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index 0ed7907fb96..3635ab3f129 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.31 2007/03/16 20:03:48 stevesk Exp $ */ +/* $OpenBSD: common.c,v 1.32 2007/09/02 15:19:38 deraadt Exp $ */ /* $NetBSD: common.c,v 1.21 2000/08/09 14:28:50 itojun Exp $ */ /* @@ -39,7 +39,7 @@ #if 0 static const char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95"; #else -static const char rcsid[] = "$OpenBSD: common.c,v 1.31 2007/03/16 20:03:48 stevesk Exp $"; +static const char rcsid[] = "$OpenBSD: common.c,v 1.32 2007/09/02 15:19:38 deraadt Exp $"; #endif #endif /* not lint */ @@ -257,7 +257,7 @@ getq(struct queue ***namelist) * and dividing it by a multiple of the minimum size entry. */ arraysz = (stbuf.st_size / 24); - queue = (struct queue **)malloc(arraysz * sizeof(struct queue *)); + queue = (struct queue **)calloc(arraysz, sizeof(struct queue *)); if (queue == NULL) goto errdone; diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index 915dbe21bdc..cbe84139a91 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpd.c,v 1.46 2007/05/05 17:13:01 stevesk Exp $ */ +/* $OpenBSD: lpd.c,v 1.47 2007/09/02 15:19:38 deraadt Exp $ */ /* $NetBSD: lpd.c,v 1.33 2002/01/21 14:42:29 wiz Exp $ */ /* @@ -41,7 +41,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; #else -static const char rcsid[] = "$OpenBSD: lpd.c,v 1.46 2007/05/05 17:13:01 stevesk Exp $"; +static const char rcsid[] = "$OpenBSD: lpd.c,v 1.47 2007/09/02 15:19:38 deraadt Exp $"; #endif #endif /* not lint */ @@ -794,7 +794,7 @@ socksetup(int af, int options, const char *port) for (r = res; r; r = r->ai_next, maxs++) ; if (socks == NULL) { - socks = malloc((maxs + 1) * sizeof(int)); + socks = calloc(maxs + 1, sizeof(int)); if (socks) *socks = 0; /* num of sockets ctr at start */ } else { diff --git a/usr.sbin/lpr/lpd/printjob.c b/usr.sbin/lpr/lpd/printjob.c index 3348672aeeb..37ef6d775f9 100644 --- a/usr.sbin/lpr/lpd/printjob.c +++ b/usr.sbin/lpr/lpd/printjob.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printjob.c,v 1.42 2007/04/07 21:57:27 stevesk Exp $ */ +/* $OpenBSD: printjob.c,v 1.43 2007/09/02 15:19:38 deraadt Exp $ */ /* $NetBSD: printjob.c,v 1.31 2002/01/21 14:42:30 wiz Exp $ */ /* @@ -1564,7 +1564,7 @@ setty(void) syslog(LOG_INFO, "%s: ioctl(TIOCGWINSZ): %m", printer); - argv = (char **)malloc(256 * sizeof(char *)); + argv = (char **)calloc(256, sizeof(char *)); if (argv == NULL) { syslog(LOG_ERR, "%s: malloc: %m", printer); exit(1); diff --git a/usr.sbin/lpr/pac/pac.c b/usr.sbin/lpr/pac/pac.c index 60d9d237f34..894699eef0b 100644 --- a/usr.sbin/lpr/pac/pac.c +++ b/usr.sbin/lpr/pac/pac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pac.c,v 1.17 2003/06/02 23:36:53 millert Exp $ */ +/* $OpenBSD: pac.c,v 1.18 2007/09/02 15:19:39 deraadt Exp $ */ /* $NetBSD: pac.c,v 1.14 2000/04/27 13:40:18 msaitoh Exp $ */ /* @@ -41,7 +41,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)pac.c 8.1 (Berkeley) 6/6/93"; #else -static const char rcsid[] = "$OpenBSD: pac.c,v 1.17 2003/06/02 23:36:53 millert Exp $"; +static const char rcsid[] = "$OpenBSD: pac.c,v 1.18 2007/09/02 15:19:39 deraadt Exp $"; #endif #endif /* not lint */ @@ -286,7 +286,7 @@ dumpit(void) hp = hashtab[0]; hno = 1; - base = (struct hent **) malloc(hcount * sizeof(hp)); + base = (struct hent **) calloc(hcount, sizeof(hp)); if (base == NULL) err(1, NULL); for (ap = base, c = hcount; c--; ap++) { diff --git a/usr.sbin/mailwrapper/mailwrapper.c b/usr.sbin/mailwrapper/mailwrapper.c index 121fb0bc926..d8e1deb2319 100644 --- a/usr.sbin/mailwrapper/mailwrapper.c +++ b/usr.sbin/mailwrapper/mailwrapper.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mailwrapper.c,v 1.16 2004/07/06 03:38:14 millert Exp $ */ +/* $OpenBSD: mailwrapper.c,v 1.17 2007/09/02 15:19:39 deraadt Exp $ */ /* $NetBSD: mailwrapper.c,v 1.2 1999/02/20 22:10:07 thorpej Exp $ */ /* @@ -60,7 +60,7 @@ initarg(struct arglist *al) { al->argc = 0; al->maxc = 10; - if ((al->argv = malloc(al->maxc * sizeof(char *))) == NULL) + if ((al->argv = calloc(al->maxc, sizeof(char *))) == NULL) err(1, "malloc"); } diff --git a/usr.sbin/memconfig/memconfig.c b/usr.sbin/memconfig/memconfig.c index 27ac18c07de..12b6ebdea3e 100644 --- a/usr.sbin/memconfig/memconfig.c +++ b/usr.sbin/memconfig/memconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memconfig.c,v 1.11 2006/03/14 19:23:16 moritz Exp $ */ +/* $OpenBSD: memconfig.c,v 1.12 2007/09/02 15:19:39 deraadt Exp $ */ /*- * Copyright (c) 1999 Michael Smith @@ -134,7 +134,7 @@ mrgetall(int memfd, int *nmr) err(1, "can't size range descriptor array"); *nmr = mro.mo_arg[0]; - mrd = malloc(*nmr * sizeof(struct mem_range_desc)); + mrd = calloc(*nmr, sizeof(struct mem_range_desc)); if (mrd == NULL) errx(1, "can't allocate %zu bytes for %d range descriptors", *nmr * sizeof(struct mem_range_desc), *nmr); diff --git a/usr.sbin/mrinfo/mrinfo.c b/usr.sbin/mrinfo/mrinfo.c index f2241f0c55c..376f0450502 100644 --- a/usr.sbin/mrinfo/mrinfo.c +++ b/usr.sbin/mrinfo/mrinfo.c @@ -76,7 +76,7 @@ #ifndef lint static char rcsid[] = - "@(#) $OpenBSD: mrinfo.c,v 1.21 2005/06/20 14:48:26 robert Exp $"; + "@(#) $OpenBSD: mrinfo.c,v 1.22 2007/09/02 15:19:39 deraadt Exp $"; /* original rcsid: "@(#) Header: mrinfo.c,v 1.6 93/04/08 15:14:16 van Exp (LBL)"; */ @@ -355,7 +355,7 @@ main(int argc, char *argv[]) if ((target_addr = inet_addr(host)) != -1) { hp = &bogus; hp->h_length = sizeof(target_addr); - if (!(hp->h_addr_list = (char **)malloc(2 * sizeof(char *)))) + if (!(hp->h_addr_list = (char **)calloc(2, sizeof(char *)))) err(1, "can't allocate memory"); if (!(hp->h_addr_list[0] = malloc(hp->h_length))) err(1, "can't allocate memory"); diff --git a/usr.sbin/ppp/ppp/route.c b/usr.sbin/ppp/ppp/route.c index b045ee693a6..703842d0389 100644 --- a/usr.sbin/ppp/ppp/route.c +++ b/usr.sbin/ppp/ppp/route.c @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: route.c,v 1.34 2005/07/17 20:43:14 brad Exp $ + * $OpenBSD: route.c,v 1.35 2007/09/02 15:19:39 deraadt Exp $ */ #include @@ -262,7 +262,7 @@ Index2Nam(int idx) if (had) newifs = (char **)realloc(ifs, sizeof(char *) * have); else - newifs = (char **)malloc(sizeof(char *) * have); + newifs = (char **)calloc(sizeof(char *), have); if (!newifs) { log_Printf(LogDEBUG, "Index2Nam: %s\n", strerror(errno)); route_nifs = 0; diff --git a/usr.sbin/pppd/main.c b/usr.sbin/pppd/main.c index ac35acb366a..5703590365c 100644 --- a/usr.sbin/pppd/main.c +++ b/usr.sbin/pppd/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.46 2007/06/04 14:59:45 henning Exp $ */ +/* $OpenBSD: main.c,v 1.47 2007/09/02 15:19:39 deraadt Exp $ */ /* * main.c - Point-to-Point Protocol main module @@ -46,7 +46,7 @@ #if 0 static char rcsid[] = "Id: main.c,v 1.49 1998/05/05 05:24:17 paulus Exp $"; #else -static char rcsid[] = "$OpenBSD: main.c,v 1.46 2007/06/04 14:59:45 henning Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.47 2007/09/02 15:19:39 deraadt Exp $"; #endif #endif @@ -1657,7 +1657,7 @@ script_setenv(var, value) } } else { i = 0; - script_env = (char **) malloc(16 * sizeof(char *)); + script_env = (char **) calloc(16, sizeof(char *)); if (script_env == 0) novm("script_setenv"); s_env_nalloc = 16; diff --git a/usr.sbin/procmap/procmap.c b/usr.sbin/procmap/procmap.c index fe724a7788d..682309d91d5 100644 --- a/usr.sbin/procmap/procmap.c +++ b/usr.sbin/procmap/procmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: procmap.c,v 1.25 2007/05/31 18:22:25 thib Exp $ */ +/* $OpenBSD: procmap.c,v 1.26 2007/09/02 15:19:40 deraadt Exp $ */ /* $NetBSD: pmap.c,v 1.1 2002/09/01 20:32:44 atatat Exp $ */ /* @@ -870,7 +870,7 @@ load_name_cache(kvm_t *kd) LIST_INIT(&lcache); _KDEREF(kd, nchash_addr, &nchash, sizeof(nchash)); - nchashtbl = malloc(sizeof(nchashtbl) * (int)nchash); + nchashtbl = calloc(sizeof(nchashtbl), (int)nchash); if (nchashtbl == NULL) err(1, "load_name_cache"); _KDEREF(kd, nchashtbl_addr, nchashtbl, diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index 5fc9deca33d..fb1aefe54d4 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pstat.c,v 1.64 2006/06/04 01:39:32 deraadt Exp $ */ +/* $OpenBSD: pstat.c,v 1.65 2007/09/02 15:19:40 deraadt Exp $ */ /* $NetBSD: pstat.c,v 1.27 1996/10/23 22:50:06 cgd Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 from: static char sccsid[] = "@(#)pstat.c 8.9 (Berkeley) 2/16/94"; #else -static char *rcsid = "$OpenBSD: pstat.c,v 1.64 2006/06/04 01:39:32 deraadt Exp $"; +static char *rcsid = "$OpenBSD: pstat.c,v 1.65 2007/09/02 15:19:40 deraadt Exp $"; #endif #endif /* not lint */ @@ -1015,7 +1015,7 @@ swapmode(void) "Total", hlen, 0, 0, 0, 0.0); return; } - if ((swdev = malloc(nswap * sizeof(*swdev))) == NULL) + if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL) err(1, "malloc"); if (swapctl(SWAP_STATS, swdev, nswap) == -1) err(1, "swapctl"); diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 3760aa19a82..2bfd2375208 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: quot.c,v 1.17 2007/07/04 17:14:45 millert Exp $ */ +/* $OpenBSD: quot.c,v 1.18 2007/09/02 15:19:40 deraadt Exp $ */ /* * Copyright (C) 1991, 1994 Wolfgang Solfrank. @@ -32,7 +32,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: quot.c,v 1.17 2007/07/04 17:14:45 millert Exp $"; +static char rcsid[] = "$Id: quot.c,v 1.18 2007/09/02 15:19:40 deraadt Exp $"; #endif /* not lint */ #include @@ -437,7 +437,7 @@ douser(int fd, struct fs *super, char *name) else if (errno) err(1, "%s", name); } - if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user)))) + if (!(usrs = (struct user *)calloc(nusers, sizeof(struct user)))) err(1, "allocate users"); memcpy(usrs, users, nusers * sizeof(struct user)); sortusers(usrs); diff --git a/usr.sbin/sasyncd/pfkey.c b/usr.sbin/sasyncd/pfkey.c index 2fac3058668..35431656f28 100644 --- a/usr.sbin/sasyncd/pfkey.c +++ b/usr.sbin/sasyncd/pfkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkey.c,v 1.18 2006/09/01 01:13:25 mpf Exp $ */ +/* $OpenBSD: pfkey.c,v 1.19 2007/09/02 15:19:40 deraadt Exp $ */ /* * Copyright (c) 2005 Håkan Olsson. All rights reserved. @@ -487,7 +487,7 @@ pfkey_snapshot(void *v) continue; /* Allocate msgbuffer, net_queue() will free it. */ - sendbuf = (u_int8_t *)malloc(m->sadb_msg_len * CHUNK); + sendbuf = (u_int8_t *)calloc(m->sadb_msg_len, CHUNK); if (sendbuf) { memcpy(sendbuf, m, m->sadb_msg_len * CHUNK); net_queue(p, MSG_PFKEYDATA, sendbuf, @@ -517,7 +517,7 @@ pfkey_snapshot(void *v) continue; /* Allocate msgbuffer, freed by net_queue(). */ - sendbuf = (u_int8_t *)malloc(m->sadb_msg_len * CHUNK); + sendbuf = (u_int8_t *)calloc(m->sadb_msg_len, CHUNK); if (sendbuf) { memcpy(sendbuf, m, m->sadb_msg_len * CHUNK); net_queue(p, MSG_PFKEYDATA, sendbuf, -- cgit v1.2.3