On Tue, Apr 22, 2014 at 12:45:25AM -0400, Peter Malone wrote:
> Hi,
>
> malloc & memset can be replaced with calloc in ping.c. Please see below for
> patch details:
Better rework this to get rid of fdmasks.
-Otto
>
> Index: ping.c
> ===================================================================
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.100
> diff -u -p -u -r1.100 ping.c
> --- ping.c 24 Mar 2014 11:11:49 -0000 1.100
> +++ ping.c 22 Apr 2014 04:41:56 -0000
> @@ -508,8 +508,8 @@ main(int argc, char *argv[])
> catcher(0); /* start things going */
>
> fdmasks = howmany(s+1, NFDBITS) * sizeof(fd_mask);
> - if ((fdmaskp = (fd_set *)malloc(fdmasks)) == NULL)
> - err(1, "malloc");
> + if ((fdmaskp = calloc(1, fdmasks)) == NULL)
> + err(1, "calloc");
>
> for (;;) {
> struct sockaddr_in from;
> @@ -521,7 +521,6 @@ main(int argc, char *argv[])
> pinger();
> timeout.tv_sec = 0;
> timeout.tv_usec = 10000;
> - memset(fdmaskp, 0, fdmasks);
> FD_SET(s, fdmaskp);
> if (select(s + 1, (fd_set *)fdmaskp, (fd_set *)NULL,
> (fd_set *)NULL, &timeout) < 1)
>