From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13869 invoked from network); 24 Jul 2008 17:17:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Jul 2008 17:17:04 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 69216 invoked from network); 24 Jul 2008 17:16:59 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Jul 2008 17:16:59 -0000 Received: (qmail 8816 invoked by alias); 24 Jul 2008 17:16:57 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25337 Received: (qmail 8807 invoked from network); 24 Jul 2008 17:16:57 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 24 Jul 2008 17:16:57 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [217.69.20.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id 8FC8480561C3 for ; Thu, 24 Jul 2008 19:16:43 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly14d.srv.mailcontrol.com (MailControl) with ESMTP id m6OHGeMH010863 for ; Thu, 24 Jul 2008 18:16:41 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Thu, 24 Jul 2008 18:16:36 +0100 Date: Thu, 24 Jul 2008 18:16:36 +0100 From: Peter Stephenson To: "Zsh hackers list" Subject: Re: Bug(?) in builtin r Message-ID: <20080724181636.5dd92ddd@news01> In-Reply-To: <2d460de70807240752ge3b0a5qbfa640585c101c35@mail.gmail.com> References: <2d460de70807240752ge3b0a5qbfa640585c101c35@mail.gmail.com> Organization: CSR X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 24 Jul 2008 17:16:36.0698 (UTC) FILETIME=[074473A0:01C8EDB1] X-Scanned-By: MailControl A-08-50-03 (www.mailcontrol.com) on 10.68.0.124 X-Virus-Scanned: ClamAV 0.92.1/7815/Thu Jul 24 17:09:44 2008 on bifrost X-Virus-Status: Clean On Thu, 24 Jul 2008 16:52:39 +0200 "Richard Hartmann" 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 Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070