diff options
author | Lawrence Teo <lteo@cvs.openbsd.org> | 2014-03-14 03:44:14 +0000 |
---|---|---|
committer | Lawrence Teo <lteo@cvs.openbsd.org> | 2014-03-14 03:44:14 +0000 |
commit | 96a5a28bd42fb844a7b51af36e600ae0ba5a2f50 (patch) | |
tree | 085ca0b13b253e1fcfacfb394beab5a079bd2b9d | |
parent | f1678ffc1d41703135c2217a06c0bcc851d7dbca (diff) |
Change a few malloc+memset calls to calloc.
ok deraadt@ florian@
-rw-r--r-- | lib/libpcap/gencode.c | 7 | ||||
-rw-r--r-- | lib/libpcap/pcap-bpf.c | 5 | ||||
-rw-r--r-- | lib/libpcap/pcap.c | 5 | ||||
-rw-r--r-- | lib/libpcap/savefile.c | 5 |
4 files changed, 9 insertions, 13 deletions
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c index 5d77801b279..2b62858ba44 100644 --- a/lib/libpcap/gencode.c +++ b/lib/libpcap/gencode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gencode.c,v 1.36 2010/10/09 08:14:36 canacar Exp $ */ +/* $OpenBSD: gencode.c,v 1.37 2014/03/14 03:44:13 lteo Exp $ */ /* * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 @@ -191,11 +191,10 @@ newchunk(n) if (k >= NCHUNKS) bpf_error("out of memory"); size = CHUNK0SIZE << k; - cp->m = (void *)malloc(size); + cp->m = (void *)calloc(1, size); if (cp->m == NULL) bpf_error("out of memory"); - - memset((char *)cp->m, 0, size); + cp->n_left = size; if (n > size) bpf_error("out of memory"); diff --git a/lib/libpcap/pcap-bpf.c b/lib/libpcap/pcap-bpf.c index 6c1e073cb70..758572d7cf2 100644 --- a/lib/libpcap/pcap-bpf.c +++ b/lib/libpcap/pcap-bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap-bpf.c,v 1.22 2013/12/03 00:25:34 deraadt Exp $ */ +/* $OpenBSD: pcap-bpf.c,v 1.23 2014/03/14 03:44:13 lteo Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1998 @@ -895,13 +895,12 @@ pcap_create(const char *device, char *ebuf) { pcap_t *p; - p = malloc(sizeof(*p)); + p = calloc(1, sizeof(*p)); if (p == NULL) { snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno)); return (NULL); } - memset(p, 0, sizeof(*p)); p->fd = -1; /* not opened yet */ p->opt.source = strdup(device); diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c index 591094fd2e7..9403efa340b 100644 --- a/lib/libpcap/pcap.c +++ b/lib/libpcap/pcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcap.c,v 1.13 2012/05/25 01:58:08 lteo Exp $ */ +/* $OpenBSD: pcap.c,v 1.14 2014/03/14 03:44:13 lteo Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998 @@ -612,10 +612,9 @@ pcap_open_dead(int linktype, int snaplen) { pcap_t *p; - p = malloc(sizeof(*p)); + p = calloc(1, sizeof(*p)); if (p == NULL) return NULL; - memset (p, 0, sizeof(*p)); p->snapshot = snaplen; p->linktype = linktype; p->fd = -1; diff --git a/lib/libpcap/savefile.c b/lib/libpcap/savefile.c index c0527bacf3b..1411081f258 100644 --- a/lib/libpcap/savefile.c +++ b/lib/libpcap/savefile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: savefile.c,v 1.10 2012/05/25 01:58:08 lteo Exp $ */ +/* $OpenBSD: savefile.c,v 1.11 2014/03/14 03:44:13 lteo Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996, 1997 @@ -129,13 +129,12 @@ pcap_fopen_offline(FILE *fp, char *errbuf) struct pcap_file_header hdr; int linklen; - p = (pcap_t *)malloc(sizeof(*p)); + p = (pcap_t *)calloc(1, sizeof(*p)); if (p == NULL) { strlcpy(errbuf, "out of swap", PCAP_ERRBUF_SIZE); return (NULL); } - memset((char *)p, 0, sizeof(*p)); /* * Set this field so we don't double-close in pcap_close! */ |