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

Re: [PATCH] Re: RFC: region_highlight inter-plugin interoperability: echo service?



Daniel Shahaf wrote on Thu, 18 Jun 2020 10:33 +0000:
> +++ b/Src/Zle/zle_refresh.c
> @@ -414,16 +414,19 @@ get_region_highlight(UNUSED(Param pm))
>  	 arrsize--;
>  	 rhp++, arrp++) {
>  	char digbuf1[DIGBUFSIZE], digbuf2[DIGBUFSIZE];
> -	int atrlen = 0, alloclen;
> +	int atrlen, alloclen;
> +	const char memo_equals[] = "memo=";
>  
>  	sprintf(digbuf1, "%d", rhp->start);
>  	sprintf(digbuf2, "%d", rhp->end);
>  
>  	atrlen = output_highlight(rhp->atr, NULL);
>  	alloclen = atrlen + strlen(digbuf1) + strlen(digbuf2) +
> -	    3; /* 2 spaces, 1 0 */
> +	    3; /* 2 spaces, 1 terminating NUL */
>  	if (rhp->flags & ZRH_PREDISPLAY)
>  	    alloclen += 2; /* "P " */
> +	if (rhp->memo)
> +	    alloclen += 1 /* space */ + strlen(memo_equals) + strlen(rhp->memo);
>  	*arrp = (char *)zhalloc(alloclen * sizeof(char));
>  	/*
>  	 * On input we allow a space after the flags.
> @@ -436,6 +439,12 @@ get_region_highlight(UNUSED(Param pm))
>  		(rhp->flags & ZRH_PREDISPLAY) ? "P" : "",
>  		digbuf1, digbuf2);
>  	(void)output_highlight(rhp->atr, *arrp + strlen(*arrp));
> +
> +	if (rhp->memo) {
> +	    strcat(*arrp, " ");
> +	    strcat(*arrp, memo_equals);
> +	    strcat(*arrp, rhp->memo);
> +	}
>      }  
>      *arrp = NULL;
>      return retarr;
> +++ b/Src/Zle/zle_utils.c
> @@ -557,6 +557,22 @@ zlegetline(int *ll, int *cs)
> +/*
> + * free() the 'memo' elements of region_highlights.
> + */
> +
> +/**/
> +void
> +free_region_highlights_memos(void)
> +{
> +    struct region_highlight *rhp;
> +    for (rhp = region_highlights;
> +	 rhp < region_highlights + n_region_highlights;
> +	 rhp++) {
> +	zsfree(rhp->memo);

s/zsfree/zfree/

since the calculation of alloclen in get_region_highlight() can result
in an alloclen that's different to strlen(rhp->memo)+1 — at least when
the ZRH_PREDISPLAY bit is set.

(This only matters for --enable-zsh-mem builds, and even then only if
alloclen happens to be exactly the one value that will cause zfree()'s
fr_rec condition's truth value to flip, but still.)

Cheers,

Daniel

> +    }
> +}  



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