Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Dec 2016 16:49:10 -0500
From:      Pedro Giffuni <pfg@FreeBSD.org>
To:        Ngie Cooper <ngie@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r310984 - head/lib/libc/net
Message-ID:  <7914bb49-6bef-6bbd-5574-ceb29f318c01@FreeBSD.org>
In-Reply-To: <201612312100.uBVL09RR092355@repo.freebsd.org>
References:  <201612312100.uBVL09RR092355@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help


On 12/31/16 16:00, Ngie Cooper wrote:
> Author: ngie
> Date: Sat Dec 31 21:00:08 2016
> New Revision: 310984
> URL: https://svnweb.freebsd.org/changeset/base/310984
>
> Log:
>   Use calloc instead of malloc + memset(.., 0, ..)
>
>   MFC after:	1 week
>
> Modified:
>   head/lib/libc/net/getaddrinfo.c
>
> Modified: head/lib/libc/net/getaddrinfo.c
> ==============================================================================
> --- head/lib/libc/net/getaddrinfo.c	Sat Dec 31 19:59:31 2016	(r310983)
> +++ head/lib/libc/net/getaddrinfo.c	Sat Dec 31 21:00:08 2016	(r310984)
> @@ -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 */

This should be calloc(n, sizeof(*aio)))

FWIW, the other cases are not very useful.
Generally, replacing any malloc(x) with a calloc(1, x) doesn't bring any 
advantage as it won't catch any overflow.

Pedro.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7914bb49-6bef-6bbd-5574-ceb29f318c01>