Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: crash/hang with gcc 5+ -O2 and --enable-zsh-mem



On Sat, 24 Feb 2018 21:06:37 -1000
Joey Pabalinas <joeypabalinas@xxxxxxxxx> wrote:
> diff --git a/Src/mem.c b/Src/mem.c
> index 840bbb6e4a4eb6fd73..f1208197b3ddac2139 100644
> --- a/Src/mem.c
> +++ b/Src/mem.c
> @@ -1719,7 +1719,13 @@ calloc(MALLOC_ARG_T n, MALLOC_ARG_T size)
>      if (!(l = n * size))
>  	return (MALLOC_RET_T) m_high;
>  
> -    r = malloc(l);
> +    /*
> +     * use realloc() (with a NULL `p` argument it behaves exactly the same
> +     * as malloc() does) to prevent an infinite loop caused by sibling-call
> +     * optimizations (the malloc() call would otherwise be replaced by an
> +     * unconditional branch back to line 1719 ad infinitum).
> +     */
> +    r = realloc(NULL, l);
>  
>      memset(r, 0, l);

Was going to object some older realloc()s don't support that behaviour,
but this is quite specifically in zsh memory management where realloc()
is explicitly defined, duh.

Can't see a problem with this apart from a minor performance hit.
calloc isn't used anywhere this would be a big deal, I don't think.  I
committed it, thanks.

I suppose gcc really wants looking at too...

pws



Messages sorted by: Reverse Date, Date, Thread, Author