diff options
author | Enji Cooper <ngie@FreeBSD.org> | 2016-12-31 21:00:08 +0000 |
---|---|---|
committer | Enji Cooper <ngie@FreeBSD.org> | 2016-12-31 21:00:08 +0000 |
commit | c5c2166d45d28dee29bc34fb283b320f8dcd4941 (patch) | |
tree | fed04a8a7e76ad1bad785fcc33ef936e726af5c3 /lib | |
parent | 41b0046a4d12f1f369cf190eaccd5857b86f6da3 (diff) | |
download | src-c5c2166d45d28dee29bc34fb283b320f8dcd4941.tar.gz src-c5c2166d45d28dee29bc34fb283b320f8dcd4941.zip |
Use calloc instead of malloc + memset(.., 0, ..)
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=310984
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index f5271c6d5a3b..0a1619cba091 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(1, sizeof(*aio) * n)) == 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; |