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

Re: crash/memory corruption when completing dynamic named directory



On Sun, 27 Mar 2011 13:37:01 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > pws, afaict, only the first little bit of zlemetaline is needed for
> > this, ie the outcs calculation. Would it be okay to split this out to
> > a separate function and call that from get_cursor and stringaszleline?
> > Otherwise we have to copy zlemetaline first and then run
> > stringaszleline, and discard all that work, which seems silly. Or does
> > outcs actually depend on the conversion too? There's a comment that
> > suggests it doesn't, but there are some assignments to it further
> > down.

I think that would be OK.  The focus of the conversion stuff when it was
written was to be effective rather than efficient, so there are no doubt
lots of optimisations of this sort.

> Here's a patch for copying the string and doing all the work, which
> I've confirmed fixes the issue.
> 
> diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
> index 98091b2..2c35874 100644
> --- a/Src/Zle/zle_params.c
> +++ b/Src/Zle/zle_params.c
> @@ -233,8 +233,10 @@ get_cursor(UNUSED(Param pm))
>  	/* A lot of work for one number, but still... */
>  	ZLE_STRING_T tmpline;
>  	int tmpcs, tmpll, tmpsz;
> -	tmpline = stringaszleline(zlemetaline, zlemetacs,
> +	char *tmpmetaline = ztrdup(zlemetaline);
> +	tmpline = stringaszleline(tmpmetaline, zlemetacs,
>  				  &tmpll, &tmpsz, &tmpcs);
> +	free(tmpmetaline);
>  	free(tmpline);
>  	return tmpcs;
>      }

Thanks, I'll commit this.

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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