zsh-workers
 help / color / mirror / code / Atom feed
* Bug in history changes
@ 2002-02-20 17:00 Peter Stephenson
  2002-02-20 19:30 ` Wayne Davison
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2002-02-20 17:00 UTC (permalink / raw)
  To: Zsh hackers list

The latest version of the history code is causing zcalc to crash.  zcalc
now tries to use its own separate history file; it's a bit hacky because
the history interface isn't intended for use like this.  The instruction
that triggers it is setting HISTSIZE to 0.

(gdb) bt
#0  0x3b200 in putoldhistentryontop (keep_going=-3664) at ../../Src/hist.c:937
#1  0x3ce44 in resizehistents () at ../../Src/hist.c:1776
#2  0x5d9c4 in histsizesetfn (pm=0x9b330, v=4294967296)
    at ../../Src/params.c:2915
#3  0x5a728 in setstrvalue (v=0xffbee7f0, val=0xef3a8 "0")
    at ../../Src/params.c:1637
#4  0x5b740 in assignsparam (s=0xbbfe0 "", val=0xef3a8 "0", augment=0)
    at ../../Src/params.c:1991
#5  0x1ef64 in typeset_single (cname=0xbbfd0 "local", 
    pname=0xbbfd8 "HISTSIZE", pm=0x9b330, func=0, on=131072, off=0, roff=0, 
    value=0xbbfe1 "0", altpm=0x0) at ../../Src/builtin.c:1868
#6  0x203f0 in bin_typeset (name=0xbbfd0 "local", argv=0xffbee9bc, 
    ops=0xffbee9d0 "", func=0) at ../../Src/builtin.c:2127
#7  0x1aa04 in execbuiltin (args=0xbbfb0, bn=0x99c50)
    at ../../Src/builtin.c:377
#8  0x2df58 in execcmd (state=0xffbeed80, input=0, output=0, how=2, last1=2)
    at ../../Src/exec.c:2306
#9  0x2b2b4 in execpline2 (state=0xffbeed80, pcode=192, how=2, input=0, 
    output=0, last1=0) at ../../Src/exec.c:1201
#10 0x2a808 in execpline (state=0xffbeed80, slcode=128, how=2, last1=0)
    at ../../Src/exec.c:991
#11 0x2a2a8 in execlist (state=0xffbeed80, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:826
#12 0x29fb0 in execode (p=0xf37c8, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:729
#13 0x2ffac in execautofn (state=0xd5de8, do_exec=0) at ../../Src/exec.c:3245
#14 0x2dd0c in execcmd (state=0xffbef130, input=0, output=0, how=18, last1=2)
    at ../../Src/exec.c:2253
#15 0x2b2b4 in execpline2 (state=0xffbef130, pcode=0, how=18, input=0, 
    output=0, last1=0) at ../../Src/exec.c:1201
#16 0x2a808 in execpline (state=0xffbef130, slcode=96, how=18, last1=0)
    at ../../Src/exec.c:991
#17 0x2a2a8 in execlist (state=0xffbef130, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:826
#18 0x29fb0 in execode (p=0xf32e8, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:729
#19 0x30630 in runshfunc (prog=0xf32e8, wrap=0x0, name=0xbbdf8 "zcalc")
    at ../../Src/exec.c:3492
#20 0x303f4 in doshfunc (name=0xca520 "zcalc", prog=0xf32e8, doshargs=0xef3d0, 
    flags=0, noreturnval=0) at ../../Src/exec.c:3407
#21 0x2ff38 in execshfunc (shf=0xd5de8, args=0xbbdd0) at ../../Src/exec.c:3217
#22 0x2decc in execcmd (state=0xffbef670, input=0, output=0, how=18, last1=2)
    at ../../Src/exec.c:2295
#23 0x2b2b4 in execpline2 (state=0xffbef670, pcode=4, how=18, input=0, 
    output=0, last1=0) at ../../Src/exec.c:1201
#24 0x2a808 in execpline (state=0xffbef670, slcode=96, how=18, last1=0)
    at ../../Src/exec.c:991
#25 0x2a2a8 in execlist (state=0xffbef670, dont_change_job=0, exiting=0)
    at ../../Src/exec.c:826
#26 0x29fb0 in execode (p=0xbbd88, dont_change_job=0, exiting=0)
    at ../../Src/exec.c:729
#27 0x3e3a8 in loop (toplevel=1, justonce=0) at ../../Src/init.c:165
#28 0x40ad0 in zsh_main (argc=1, argv=0x1) at ../../Src/init.c:1214
#29 0x1a220 in main (argc=1, argv=0xffbef844) at ../../Src/main.c:37

    if (he != hist_ring->down) {
=>	he->up->down = he->down;
	he->down->up = he->up;
	he->up = hist_ring;
	he->down = hist_ring->down;
	hist_ring->down = he->down->up = he;
    }

(gdb) p he->up
$1 = 0xffffffff

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Bug in history changes
  2002-02-20 17:00 Bug in history changes Peter Stephenson
@ 2002-02-20 19:30 ` Wayne Davison
  2002-02-21 13:07   ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Wayne Davison @ 2002-02-20 19:30 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Wed, 20 Feb 2002, Peter Stephenson wrote:
> The latest version of the history code is causing zcalc to crash.

I'm ashamed to say that my last patch still left a stupid bug in
prepnexthistent().  I just committed the following fix to CVS.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/hist.c
--- Src/hist.c	18 Feb 2002 19:25:25 -0000	1.41
+++ Src/hist.c	20 Feb 2002 19:22:20 -0000
@@ -971,7 +971,8 @@
     }
     else {
 	putoldhistentryontop(0);
-	freehistdata(he = hist_ring, 0);
+	freehistdata(hist_ring, 0);
+	he = hist_ring;
     }
     he->histnum = ++curhist;
     if (curline_in_ring)
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


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

* Re: Bug in history changes
  2002-02-20 19:30 ` Wayne Davison
@ 2002-02-21 13:07   ` Peter Stephenson
  2002-02-22 11:19     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2002-02-21 13:07 UTC (permalink / raw)
  To: Zsh hackers list

Wayne Davison wrote:
> On Wed, 20 Feb 2002, Peter Stephenson wrote:
> > The latest version of the history code is causing zcalc to crash.
> 
> I'm ashamed to say that my last patch still left a stupid bug in
> prepnexthistent().  I just committed the following fix to CVS.

I'm still getting the crash after recompiling.


+13:06% zcalc
zsh: bus error (core dumped)  ./zsh
13:06(138)% gdb zsh core
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.6"...
Core was generated by `./zsh'.
Program terminated with signal 10, Bus Error.
Reading symbols from /usr/lib/libsocket.so.1...done.
Reading symbols from /usr/lib/libdl.so.1...done.
Reading symbols from /usr/lib/libnsl.so.1...done.
Reading symbols from /usr/lib/libm.so.1...done.
Reading symbols from /usr/lib/libc.so.1...done.
Reading symbols from /usr/lib/libmp.so.2...done.
Reading symbols from /usr/platform/SUNW,Sun-Fire-280R/lib/libc_psr.so.1...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/net/tcp.so...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/zle.so...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/complete.so...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/zutil.so...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/compctl.so...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/parameter.so...done.
Reading symbols from /home/pws/lib/zsh/4.1.0-dev-3/zsh/complist.so...done.
---Type <return> to continue, or q <return> to quit---
#0  0x3b168 in putoldhistentryontop (keep_going=10504) at ../../Src/hist.c:937
937             he->up->down = he->down;
(gdb) bt
#0  0x3b168 in putoldhistentryontop (keep_going=10504) at ../../Src/hist.c:937
#1  0x3cdac in resizehistents () at ../../Src/hist.c:1777
#2  0x5d92c in histsizesetfn (pm=0x9b2a8, v=4294967296)
    at ../../Src/params.c:2915
#3  0x5a690 in setstrvalue (v=0xffbee7e8, val=0xf52d8 "0")
    at ../../Src/params.c:1637
#4  0x5b6a8 in assignsparam (s=0xbbf58 "", val=0xf52d8 "0", augment=0)
    at ../../Src/params.c:1991
#5  0x1eecc in typeset_single (cname=0xbbf48 "local", 
    pname=0xbbf50 "HISTSIZE", pm=0x9b2a8, func=0, on=131072, off=0, roff=0, 
    value=0xbbf59 "0", altpm=0x0) at ../../Src/builtin.c:1875
#6  0x20358 in bin_typeset (name=0xbbf48 "local", argv=0xffbee9b4, 
    ops=0xffbee9c8 "", func=0) at ../../Src/builtin.c:2134
#7  0x1aa04 in execbuiltin (args=0xbbf28, bn=0x99bc8)
    at ../../Src/builtin.c:377
#8  0x2dec0 in execcmd (state=0xffbeed78, input=0, output=0, how=2, last1=2)
    at ../../Src/exec.c:2306
#9  0x2b21c in execpline2 (state=0xffbeed78, pcode=192, how=2, input=0, 
    output=0, last1=0) at ../../Src/exec.c:1201
#10 0x2a770 in execpline (state=0xffbeed78, slcode=128, how=2, last1=0)
    at ../../Src/exec.c:991
#11 0x2a210 in execlist (state=0xffbeed78, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:826
---Type <return> to continue, or q <return> to quit---
#12 0x29f18 in execode (p=0xf38c0, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:729
#13 0x2ff14 in execautofn (state=0xd5d60, do_exec=0) at ../../Src/exec.c:3245
#14 0x2dc74 in execcmd (state=0xffbef128, input=0, output=0, how=18, last1=2)
    at ../../Src/exec.c:2253
#15 0x2b21c in execpline2 (state=0xffbef128, pcode=0, how=18, input=0, 
    output=0, last1=0) at ../../Src/exec.c:1201
#16 0x2a770 in execpline (state=0xffbef128, slcode=96, how=18, last1=0)
    at ../../Src/exec.c:991
#17 0x2a210 in execlist (state=0xffbef128, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:826
#18 0x29f18 in execode (p=0xf3280, dont_change_job=1, exiting=0)
    at ../../Src/exec.c:729
#19 0x30598 in runshfunc (prog=0xf3280, wrap=0x0, name=0xbbd70 "zcalc")
    at ../../Src/exec.c:3492
#20 0x3035c in doshfunc (name=0xca4a8 "zcalc", prog=0xf3280, doshargs=0xf5300, 
    flags=0, noreturnval=0) at ../../Src/exec.c:3407
#21 0x2fea0 in execshfunc (shf=0xd5d60, args=0xbbd48) at ../../Src/exec.c:3217
#22 0x2de34 in execcmd (state=0xffbef668, input=0, output=0, how=18, last1=2)
    at ../../Src/exec.c:2295
#23 0x2b21c in execpline2 (state=0xffbef668, pcode=4, how=18, input=0, 
    output=0, last1=0) at ../../Src/exec.c:1201
#24 0x2a770 in execpline (state=0xffbef668, slcode=96, how=18, last1=0)
---Type <return> to continue, or q <return> to quit---
    at ../../Src/exec.c:991
#25 0x2a210 in execlist (state=0xffbef668, dont_change_job=0, exiting=0)
    at ../../Src/exec.c:826
#26 0x29f18 in execode (p=0xbbd00, dont_change_job=0, exiting=0)
    at ../../Src/exec.c:729
#27 0x3e310 in loop (toplevel=1, justonce=0) at ../../Src/init.c:165
#28 0x40a38 in zsh_main (argc=1, argv=0x1) at ../../Src/init.c:1214
#29 0x1a220 in main (argc=1, argv=0xffbef83c) at ../../Src/main.c:37
(gdb) l
932                 he = next;
933                 next = he->down;
934             } while (he != hist_ring->down && !(he->flags & HIST_DUP));
935         }
936         if (he != hist_ring->down) {
937             he->up->down = he->down;
938             he->down->up = he->up;
939             he->up = hist_ring;
940             he->down = hist_ring->down;
941             hist_ring->down = he->down->up = he;

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Bug in history changes
  2002-02-21 13:07   ` Peter Stephenson
@ 2002-02-22 11:19     ` Peter Stephenson
  2002-02-22 11:26       ` Peter Stephenson
  2002-02-22 22:00       ` Wayne Davison
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-02-22 11:19 UTC (permalink / raw)
  To: Zsh hackers list

Peter Stephenson wrote:
> Wayne Davison wrote:
> > On Wed, 20 Feb 2002, Peter Stephenson wrote:
> > > The latest version of the history code is causing zcalc to crash.
> > 
> > I'm ashamed to say that my last patch still left a stupid bug in
> > prepnexthistent().  I just committed the following fix to CVS.
> 
> I'm still getting the crash after recompiling.

It seems to be the code with HISTEXPIREDUPSFIRST in
putoldhistentryontop() setting the next pointer to something that's
about to be free, but I don't remotely understand the code well enough
to be sure.  I made it go away by setting next to NULL if it was
pointing to something that was being freed, but I have no idea if this
is correct, or if that should ever happen.

Whether or not I do that, I now get:

+11:15% unsetopt histexpiredupsfirst
+11:15% HISTSIZE=1
+11:15% h
fc: no such event: 832

This doesn't happen if HISTSIZE is 2 or larger.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Bug in history changes
  2002-02-22 11:19     ` Peter Stephenson
@ 2002-02-22 11:26       ` Peter Stephenson
  2002-02-22 22:00       ` Wayne Davison
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-02-22 11:26 UTC (permalink / raw)
  To: Zsh hackers list

Peter Stephenson wrote:
> It seems to be the code with HISTEXPIREDUPSFIRST in
> putoldhistentryontop() setting the next pointer to something that's
> about to be free, but I don't remotely understand the code well enough
> to be sure.  I made it go away by setting next to NULL if it was
> pointing to something that was being freed, but I have no idea if this
> is correct, or if that should ever happen.

Actually, I can't really see how the following fix can be far wrong.  It
fixes the crash.  It doesn't fix the other, very minor, problem.

Index: Src/hist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hist.c,v
retrieving revision 1.42
diff -u -r1.42 hist.c
--- Src/hist.c	20 Feb 2002 19:25:14 -0000	1.42
+++ Src/hist.c	22 Feb 2002 11:24:54 -0000
@@ -941,6 +941,8 @@
 	hist_ring->down = he->down->up = he;
     }
     hist_ring = he;
+    if (next == hist_ring)
+	next = hist_ring->down;
 }
 
 /**/

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


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

* Re: Bug in history changes
  2002-02-22 11:19     ` Peter Stephenson
  2002-02-22 11:26       ` Peter Stephenson
@ 2002-02-22 22:00       ` Wayne Davison
  1 sibling, 0 replies; 6+ messages in thread
From: Wayne Davison @ 2002-02-22 22:00 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Fri, 22 Feb 2002, Peter Stephenson wrote:
> It seems to be the code with HISTEXPIREDUPSFIRST in
> putoldhistentryontop() setting the next pointer to something that's
> about to be free

Right.  The forward scan has to end at just the right point for this bug
to get triggered, so I had been having a hard time getting it to crash
with my history settings.  Once I duplicated the bug, I came up with the
following patch:

Index: Src/hist.c
--- Src/hist.c	20 Feb 2002 19:25:14 -0000	1.42
+++ Src/hist.c	22 Feb 2002 20:40:29 -0000	1.43
@@ -924,14 +924,15 @@
 	if (!keep_going)
 	    max_unique_ct = getiparam("SAVEHIST");
 	do {
-	    if (max_unique_ct-- <= 0) {
+	    if (max_unique_ct-- <= 0 || he == hist_ring) {
 		max_unique_ct = 0;
 		he = hist_ring->down;
+		next = hist_ring;
 		break;
 	    }
 	    he = next;
 	    next = he->down;
-	} while (he != hist_ring->down && !(he->flags & HIST_DUP));
+	} while (!(he->flags & HIST_DUP));
     }
     if (he != hist_ring->down) {
 	he->up->down = he->down;

> +11:15% unsetopt histexpiredupsfirst
> +11:15% HISTSIZE=1
> +11:15% h
> fc: no such event: 832

The code is trying to list the (non-existent) event prior to the "h"
command and failing.  This less-than-optimal result is caused by the
code trying to deal with the differences between specified and default
values in too simplistic a manner (i.e. if the user had actually typed
"h 832 832" that would have been the right thing to output).

The following patch makes the default-list values always encompass some
history and it leaves explicitly-specified values alone (since fclist()
can handle out-of-range values, and it can output better error messages
if the range encompasses nothing).

Index: Src/builtin.c
--- Src/builtin.c	20 Feb 2002 12:51:53 -0000	1.69
+++ Src/builtin.c	22 Feb 2002 21:42:36 -0000
@@ -1308,18 +1308,23 @@
 	return 1;
     }
     /* default values of first and last, and range checking */
+    if (last == -1) {
+	if (ops['l'] && first < curhist) {
+	    last = addhistnum(curline.histnum,-1,0);
+	    if (last < firsthist())
+		last = firsthist();
+	}
+	else
+	    last = first;
+    }
     if (first == -1) {
 	first = ops['l']? addhistnum(curline.histnum,-16,0)
-	    : addhistnum(curline.histnum,-1,0);
+			: addhistnum(curline.histnum,-1,0);
+	if (first < 1)
+	    first = 1;
+	if (last < first)
+	    last = first;
     }
-    if (last == -1)
-	last = ops['l']? addhistnum(curline.histnum,-1,0) : first;
-    if (first < firsthist())
-	first = firsthist() - (last < firsthist());
-    if (last > curhist)
-	last = curhist;
-    else if (last < first)
-	last = first;
     if (ops['l']) {
 	/* list the required part of the history */
 	retval = fclist(stdout, !ops['n'], ops['r'], ops['D'],

One side-effect of this patch is that you can get reverse output just by
specifying a last number that is less than the first number (or by using
the -r option).

..wayne..


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

end of thread, other threads:[~2002-02-22 22:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-20 17:00 Bug in history changes Peter Stephenson
2002-02-20 19:30 ` Wayne Davison
2002-02-21 13:07   ` Peter Stephenson
2002-02-22 11:19     ` Peter Stephenson
2002-02-22 11:26       ` Peter Stephenson
2002-02-22 22:00       ` Wayne Davison

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