From: Harald van Dijk <harald@gigawatt.nl>
To: Zando Fardones <bluesun654@gmail.com>, dash@vger.kernel.org
Subject: Re: [BUG] Here-document redirection with vi/emacs on
Date: Fri, 30 Jun 2017 01:33:29 +0200 [thread overview]
Message-ID: <d343eac0-b110-609b-6f7e-aa85e29f9091@gigawatt.nl> (raw)
In-Reply-To: <CAPLrsYe1hemq+pOTRERmxc3M0-QrHhGm9PUOhs7pJUN5-cOk6A@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 962 bytes --]
On 27/06/17 16:29, Zando Fardones wrote:
> Hello,
>
> I think I've found a bug when using the here-document redirection in
> an interactive shell. What basically happens is that you can't see the
> command output if you set the "vi" or "emacs" options.
That's not quite what happens: the here-document contents got lost, so
there is no command output to see. Nice find.
The problem is that getprompt() is implicitly called by el_gets(). This
messes with the memory used by the parser to store the here-document's
contents. In the non-emacs/vi case, the prompt is explicitly written by
setprompt(), which wraps the getprompt() call in a
pushstackmark()/popstackmark() pair to restore the state so that parsing
can continue. But when getprompt() is called by el_gets(), it knows
nothing about this.
The whole call to el_gets() can be surrounded by another
pushstackmark()/popstackmark() pair to solve the problem, as attached.
Cheers,
Harald van Dijk
[-- Attachment #2: dash-libedit-heredoc.patch --]
[-- Type: text/x-patch, Size: 345 bytes --]
--- a/src/input.c
+++ b/src/input.c
@@ -147,8 +147,12 @@ retry:
static const char *rl_cp;
static int el_len;
- if (rl_cp == NULL)
+ if (rl_cp == NULL) {
+ struct stackmark smark;
+ pushstackmark(&smark, stackblocksize());
rl_cp = el_gets(el, &el_len);
+ popstackmark(&smark);
+ }
if (rl_cp == NULL)
nr = 0;
else {
prev parent reply other threads:[~2017-06-29 23:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-27 14:29 [BUG] Here-document redirection with vi/emacs on Zando Fardones
2017-06-29 23:33 ` Harald van Dijk [this message]
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=d343eac0-b110-609b-6f7e-aa85e29f9091@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=bluesun654@gmail.com \
--cc=dash@vger.kernel.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.
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).