Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Jan 2017 01:05:02 +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-10@freebsd.org
Subject:   svn commit: r311718 - stable/10/lib/libc/net
Message-ID:  <201701090105.v09152hO085085@repo.freebsd.org>

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

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

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

Modified: stable/10/lib/libc/net/getaddrinfo.c
==============================================================================
--- stable/10/lib/libc/net/getaddrinfo.c	Mon Jan  9 01:02:16 2017	(r311717)
+++ stable/10/lib/libc/net/getaddrinfo.c	Mon Jan  9 01:05:02 2017	(r311718)
@@ -673,9 +673,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);
@@ -1454,9 +1453,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);
@@ -1876,8 +1874,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 +
@@ -1890,8 +1887,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?201701090105.v09152hO085085>