zsh-workers
 help / color / mirror / code / Atom feed
* fc -lr broken in current git?
@ 2012-04-30 12:07 Hauke Petersen
  2012-04-30 12:46 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Hauke Petersen @ 2012-04-30 12:07 UTC (permalink / raw)
  To: zsh-workers

fc -lr seems to be problematic in current git:

     % zsh -f
     % fc -lr
         1  fc -lr
     % fc -lr
         1  fc -lr
     % fc -lr
     fc: history events are in wrong order, aborted
     %

Please note that a) it doesn't happen without the -r option, and b) -r 
works fine with the tarred 4.3.17 sources.

This does not seem to be connected to 
<http://www.zsh.org/mla/workers/2012/msg00361.html> as I've tried with 
or without the patch at the time.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fc -lr broken in current git?
  2012-04-30 12:07 fc -lr broken in current git? Hauke Petersen
@ 2012-04-30 12:46 ` Peter Stephenson
  2012-05-03  9:17   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2012-04-30 12:46 UTC (permalink / raw)
  To: zsh-workers

On Mon, 30 Apr 2012 14:07:09 +0200
Hauke Petersen <hkptrsn@googlemail.com> wrote:
> fc -lr seems to be problematic in current git:

Yes, it doesn't take account of the -r flag.

I wonder if a better fix is only to check the order when actually
executing code, which is where the problems happened.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.256
diff -p -u -r1.256 builtin.c
--- Src/builtin.c	7 Mar 2012 06:10:42 -0000	1.256
+++ Src/builtin.c	30 Apr 2012 12:45:12 -0000
@@ -1641,7 +1641,7 @@ static int
 fclist(FILE *f, Options ops, zlong first, zlong last,
        struct asgment *subs, Patprog pprog)
 {
-    int fclistdone = 0;
+    int fclistdone = 0, wrong_order;
     zlong tmp;
     char *s, *tdfmt, *timebuf;
     Histent ent;
@@ -1651,8 +1651,11 @@ fclist(FILE *f, Options ops, zlong first
 	tmp = last;
 	last = first;
 	first = tmp;
+	wrong_order = (last > first);
+    } else {
+	wrong_order = (first > last);
     }
-    if (first > last) {
+    if (wrong_order) {
 	zwarnnam("fc", "history events are in wrong order, aborted");
 	if (f != stdout)
 	    fclose(f);

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


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fc -lr broken in current git?
  2012-04-30 12:46 ` Peter Stephenson
@ 2012-05-03  9:17   ` Peter Stephenson
  2012-05-03 15:24     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2012-05-03  9:17 UTC (permalink / raw)
  To: zsh-workers

On Mon, 30 Apr 2012 13:46:14 +0100
Peter Stephenson <Peter.Stephenson@csr.com> wrote:
> On Mon, 30 Apr 2012 14:07:09 +0200
> Hauke Petersen <hkptrsn@googlemail.com> wrote:
> > fc -lr seems to be problematic in current git:
> 
> Yes, it doesn't take account of the -r flag.
> 
> I wonder if a better fix is only to check the order when actually
> executing code, which is where the problems happened.

This will allow listing in any order, but not allow any execution out of
order, even if the -r flag is explicitly given.  That should be enough
to prevent bad behaviour; does it disallow anything useful?  I think
deliberately reversing the order of commands using the history mechanism
is a *very* abstruse use.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.256
diff -p -u -r1.256 builtin.c
--- Src/builtin.c	7 Mar 2012 06:10:42 -0000	1.256
+++ Src/builtin.c	3 May 2012 09:12:41 -0000
@@ -1498,7 +1498,7 @@ bin_fc(char *nam, char **argv, Options o
     }
     if (OPT_ISSET(ops,'l')) {
 	/* list the required part of the history */
-	retval = fclist(stdout, ops, first, last, asgf, pprog);
+	retval = fclist(stdout, ops, first, last, asgf, pprog, 0);
 	unqueue_signals();
     }
     else {
@@ -1530,7 +1530,7 @@ bin_fc(char *nam, char **argv, Options o
 		}
 	    }
 	    ops->ind['n'] = 1;	/* No line numbers here. */
-	    if (!fclist(out, ops, first, last, asgf, pprog)) {
+	    if (!fclist(out, ops, first, last, asgf, pprog, 1)) {
 		char *editor;
 
 		if (func == BIN_R)
@@ -1639,7 +1639,7 @@ fcsubs(char **sp, struct asgment *sub)
 /**/
 static int
 fclist(FILE *f, Options ops, zlong first, zlong last,
-       struct asgment *subs, Patprog pprog)
+       struct asgment *subs, Patprog pprog, int is_command)
 {
     int fclistdone = 0;
     zlong tmp;
@@ -1652,8 +1652,8 @@ fclist(FILE *f, Options ops, zlong first
 	last = first;
 	first = tmp;
     }
-    if (first > last) {
-	zwarnnam("fc", "history events are in wrong order, aborted");
+    if (is_command && first > last) {
+	zwarnnam("fc", "history events can't be executed backwards, aborted");
 	if (f != stdout)
 	    fclose(f);
 	return 1;

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


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: fc -lr broken in current git?
  2012-05-03  9:17   ` Peter Stephenson
@ 2012-05-03 15:24     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2012-05-03 15:24 UTC (permalink / raw)
  To: zsh-workers

On May 3, 10:17am, Peter Stephenson wrote:
}
} This will allow listing in any order, but not allow any execution out of
} order, even if the -r flag is explicitly given.

I think this is fine.

-- 
Barton E. Schaefer


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-03 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-30 12:07 fc -lr broken in current git? Hauke Petersen
2012-04-30 12:46 ` Peter Stephenson
2012-05-03  9:17   ` Peter Stephenson
2012-05-03 15:24     ` Bart Schaefer

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).