Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jan 2017 01:02:16 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r311717 - stable/11/lib/libc/net
Message-ID:  <201701090102.v0912Gjt084893@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Mon Jan  9 01:02:16 2017
New Revision: 311717
URL: https://svnweb.freebsd.org/changeset/base/311717

Log:
  MFC r310984,r311102:
  
  r310984:
  
  Use calloc instead of malloc + memset(.., 0, ..)
  
  r311102 (by pfg):
  
  Cleanup inelegant calloc(3) introduced in r310984.

Modified:
  stable/11/lib/libc/net/getaddrinfo.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libc/net/getaddrinfo.c
==============================================================================
--- stable/11/lib/libc/net/getaddrinfo.c	Mon Jan  9 01:00:20 2017	(r311716)
+++ stable/11/lib/libc/net/getaddrinfo.c	Mon Jan  9 01:02:16 2017	(r311717)
@@ -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, si
 		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, si
 			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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701090102.v0912Gjt084893>