zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: "Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: Re: Bug(?) in builtin r
Date: Thu, 24 Jul 2008 18:16:36 +0100	[thread overview]
Message-ID: <20080724181636.5dd92ddd@news01> (raw)
In-Reply-To: <2d460de70807240752ge3b0a5qbfa640585c101c35@mail.gmail.com>

On Thu, 24 Jul 2008 16:52:39 +0200
"Richard Hartmann" <richih.mailinglist@gmail.com> wrote:
> Hi all,
> 
> I am sure most of you are aware of this, but it has always
> ailed me and should probably be changed.
> If you have 100 commands on your stack and call
> 
>   r 101
> 
> it will recurse endlessly or as long as the box allows it to
> do until killing it. Unless there are useful aspects to this
> behaviour, it is basically a nice way to kill your shell.

Hmm... repeating the current line and doing something else with it (rather
than just repeating it) is potentially useful.  However, in zsh this is
handled recursively, so you quickly get into problems on the stack.  (I
have a suspicion in ksh it puts it onto the input stack and this problem is
avoided.)  It would therefore be safer to disallow it.

This disallows the specific case that the range includes the current
history entry and nothing before it, and there's no editor.  Otherwise it
either truncates the history so that the current line isn't included, or if
you've specified an editor it lets you edit the current line, too, if you
really want.  It's not clear that last bit is actually useful and it might
be better consistently to ignore the current history line here.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.197
diff -u -r1.197 builtin.c
--- Src/builtin.c	17 Jul 2008 11:27:57 -0000	1.197
+++ Src/builtin.c	24 Jul 2008 17:13:39 -0000
@@ -1446,20 +1446,28 @@
 	    unqueue_signals();
 	    zwarnnam("fc", "can't open temp file: %e", errno);
 	} else {
+	    char *editor;
+
+	    if (func == BIN_R)
+		editor = "-";
+	    else if (OPT_HASARG(ops, 'e'))
+		editor = OPT_ARG(ops, 'e');
+	    else
+		editor = getsparam("FCEDIT");
+	    if (!editor)
+		editor = getsparam("EDITOR");
+	    if (!editor)
+		editor = DEFAULT_FCEDIT;
+	    if (last >= curhist && !strcmp(editor, "-")) {
+		last = curhist - 1;
+		if (first > last) {
+		    unqueue_signals();
+		    zwarnnam("fc", "invalid use of current history line");
+		    return 1;
+		}
+	    }
 	    ops->ind['n'] = 1;	/* No line numbers here. */
 	    if (!fclist(out, ops, first, last, asgf, pprog)) {
-		char *editor;
-
-		if (func == BIN_R)
-		    editor = "-";
-		else if (OPT_HASARG(ops, 'e'))
-		    editor = OPT_ARG(ops, 'e');
-		else
-		    editor = getsparam("FCEDIT");
-		if (!editor)
-		    editor = getsparam("EDITOR");
-		if (!editor)
-		    editor = DEFAULT_FCEDIT;
 
 		unqueue_signals();
 		if (fcedit(editor, fil)) {

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


  parent reply	other threads:[~2008-07-24 17:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-24 14:52 Richard Hartmann
2008-07-24 16:36 ` thomasg
2008-07-24 17:16 ` Peter Stephenson [this message]
2008-07-25  8:52   ` Peter Stephenson
2008-07-27  9:05     ` Richard Hartmann
2008-07-27 17:27       ` Peter Stephenson
2008-07-27 17:41         ` Richard Hartmann

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=20080724181636.5dd92ddd@news01 \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).