From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] Re: RFC: region_highlight inter-plugin interoperability: echo service?
Date: Thu, 18 Jun 2020 11:16:26 +0000 [thread overview]
Message-ID: <20200618111626.45cd40a3@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20200618103311.62307eb5@tarpaulin.shahaf.local2>
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
> + }
> +}
next prev parent reply other threads:[~2020-06-18 11:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-06 7:20 Daniel Shahaf
2020-06-18 10:33 ` [PATCH] " Daniel Shahaf
2020-06-18 11:16 ` Daniel Shahaf [this message]
2020-06-25 12:30 ` Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200618111626.45cd40a3@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).