Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bindkey induced coredump

Mark Hanson wrote:
> $ zsh -f
> $ echo $ZSH_VERSION
> 3.0.0
> $ bindkey -v
> $ bindkey -r '\e[A'
> $ bindkey -r '\e[B'
> $ bindkey -r '\e[C'
> $ bindkey -r '\e[D'
> $ <ESC><ESC>
> coredump

Doesn't look like anybody else has had a go at this.

I think the following patch is right, but this had me confused for a
long time.  The confusion is all the different key binding tables.  I
think what's happening is this:  the last bindkey -r deletes the entry
for "\e" in keybindtab (which is vikeybindtab) since it now has
nothing attached to it in mainbindtab.  However it is still marked as
a prefix in altbindtab, which is used in vi command mode, which is
what the first <ESC> enters.  Hence the crash when zle tries to look
for a key representing the prefix on the second <ESC>.  (keybindtab,
as I understand it, is only used to resolve multi-key sequences and
the like.)

The answer seems to be to make sure the prefix entry is deleted in the
other bindtab.  It's not actually clear that one wants to remove all
those cursor key entries in the alternate keymap, but given there is
only one keybindtab for vi mode, that's currently inevitable.

The remaining question is what to set the key to in the other bindtab,
given that it was previously only set for a prefix.  The choices are
undefined or the same as in the first bindtab.  I picked the latter.

*** Src/zle_main.c.bind	Thu Sep  5 22:47:12 1996
--- Src/zle_main.c	Thu Sep 12 13:37:02 1996
*** 991,997 ****
--- 991,1005 ----
  			(ky = (Key) keybindtab->getnode(keybindtab, s))->prefixct--;
  			if (!ky->prefixct) {
+ 			    int *otab = ops['a'] ? mainbindtab : altbindtab;
  			    tab[STOUC(*s)] = ky->func;
+ 			    /*
+ 			     * If the bindtab we are not using also
+ 			     * adds this key as a prefix, it must also
+ 			     * be reset.
+ 			     */
+ 			    if (otab[STOUC(*s)] == z_prefix)
+ 				otab[STOUC(*s)] = ky->func;
  			    if (ky->func != z_sendstring)
  				free(keybindtab->removenode(keybindtab, s));

Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.

Messages sorted by: Reverse Date, Date, Thread, Author