summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-01-09 01:02:16 +0000
committerngie <ngie@FreeBSD.org>2017-01-09 01:02:16 +0000
commit038e1211ccdefb7bf6553d0fc1b26d9576344d7d (patch)
tree75a393c6349b3e2c69dd50820be94d5bb1d343dd /lib
parent5c38e13fbf76bb879889d029ece563829d7961d6 (diff)
downloadFreeBSD-src-038e1211ccdefb7bf6553d0fc1b26d9576344d7d.zip
FreeBSD-src-038e1211ccdefb7bf6553d0fc1b26d9576344d7d.tar.gz
MFC r310984,r311102:
r310984: Use calloc instead of malloc + memset(.., 0, ..) r311102 (by pfg): Cleanup inelegant calloc(3) introduced in r310984.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/getaddrinfo.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index f5271c6..5988ebc 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -691,9 +691,8 @@ reorder(struct addrinfo *sentinel)
return(n);
/* allocate a temporary array for sort and initialization of it. */
- if ((aio = malloc(sizeof(*aio) * n)) == NULL)
+ if ((aio = calloc(n, sizeof(*aio))) == NULL)
return(n); /* give up reordering */
- memset(aio, 0, sizeof(*aio) * n);
/* retrieve address selection policy from the kernel */
TAILQ_INIT(&policyhead);
@@ -1449,9 +1448,8 @@ copy_ai(const struct addrinfo *pai)
size_t l;
l = sizeof(*ai) + pai->ai_addrlen;
- if ((ai = (struct addrinfo *)malloc(l)) == NULL)
+ if ((ai = calloc(1, l)) == NULL)
return NULL;
- memset(ai, 0, l);
memcpy(ai, pai, sizeof(*ai));
ai->ai_addr = (struct sockaddr *)(void *)(ai + 1);
memcpy(ai->ai_addr, pai->ai_addr, pai->ai_addrlen);
@@ -1874,8 +1872,7 @@ addrinfo_unmarshal_func(char *buffer, size_t buffer_size, void *retval,
size = new_ai.ai_addrlen + sizeof(struct addrinfo) +
_ALIGNBYTES;
- sentinel = (struct addrinfo *)malloc(size);
- memset(sentinel, 0, size);
+ sentinel = calloc(1, size);
memcpy(sentinel, &new_ai, sizeof(struct addrinfo));
sentinel->ai_addr = (struct sockaddr *)_ALIGN((char *)sentinel +
@@ -1888,8 +1885,7 @@ addrinfo_unmarshal_func(char *buffer, size_t buffer_size, void *retval,
memcpy(&size, p, sizeof(size_t));
p += sizeof(size_t);
- sentinel->ai_canonname = (char *)malloc(size + 1);
- memset(sentinel->ai_canonname, 0, size + 1);
+ sentinel->ai_canonname = calloc(1, size + 1);
memcpy(sentinel->ai_canonname, p, size);
p += size;
OpenPOWER on IntegriCloud