Ping.
On Wed, Apr 23, 2014 at 10:48:38PM -0500, Kent R. Spillner wrote:
> The diff below removes the check for siz == 0 in xmalloc() because it is
> unnecessary.
>
> I was curious about the check for siz == 0 in xmalloc() when I first saw
> it, so I dug in further and came to the conclusion it's unnecessary:
>
> * It errors out immediately, so aside from the "zero size" specific error
> message (which users won't see anyways if they start cwm from .xinitrc
> or .xsession) it's not offering any benefit
> * malloc() accepts size zero and returns a pointer to memory that will
> SEGFAULT when accessed anyways, so removing this check isn't going to
> hide any errors
> * All but one of the existing calls to xmalloc() uses sizeof anyways, so
> there's actually very little chance of siz == 0 in practice
> * In fact, there's currently zero chance siz == 0 because the other call
> (in kbfunc_ssh(), kbfunc.c:335) actually passes the value len + 1, so
> even if len was zero -- which it isn't: the value of len comes from
> the fgetln() call on line 330, and fgetln guarantees len > 0 on
> success -- the argument to xmalloc() will always be >= 1 (Unless a
> user has line in ~/.ssh/known_hosts that is SIZE_MAX bytes long, but
> then the memcpy() on the very next line will SEGFAULT anyways)
>
>
> Index: xmalloc.c
> ===================================================================
> RCS file: /work/cvsroot/xenocara/app/cwm/xmalloc.c,v
> retrieving revision 1.12
> diff -p -u -r1.12 xmalloc.c
> --- xmalloc.c 17 Dec 2013 16:12:18 -0000 1.12
> +++ xmalloc.c 24 Apr 2014 03:24:01 -0000
> @@ -37,8 +37,6 @@ xmalloc(size_t siz)
> {
> void *p;
>
> - if (siz == 0)
> - errx(1, "xmalloc: zero size");
> if ((p = malloc(siz)) == NULL)
> err(1, "malloc");
>
>