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

Re: bug in insert-last-word?



On Tue, 21 Dec 2004, Danek Duvall wrote:

> % echo "blah
> dquote>^C
> 
> Now insert-last-word will repeatedly add '"blah' to the line, rather than
> cycling through previous lines.

This is somewhat strange.

Start as above, then also type

% { echo frob
cursh>^C

Now invoke insert-last-word repeatedly.  You get

% frob
% "blah
% "blahfrob
% "blah"blah
% "blah"blahfrob
% "blah"blah"blah
% "blah"blah"blahfrob

etc.  So I think it has something to do with the unclosed quote rather 
than with insert-last-word itself.

Sure enough, after some time with gdb, I find:

Breakpoint 1, insertlastword (args=0x8146754)
    at ../../../zsh-4.0/Src/Zle/zle_hist.c:457
457         if (lastinsert && lastlen &&
(gdb) p lastinsert
$4 = 0x817c010 "\"blah"
(gdb) p lastlen
$5 = 6

Note that the last insertion recorded was 6 characters, but in fact only 5 
characters were actually inserted on the line, because the phantom 6th 
character was a NUL byte.  This confuses the subsequent insertlastword()
call, so it doesn't delete the previous insertion and doesn't search up to
the next history line.

The trouble lies with this pair of assignments:

	s = he->text + he->words[2*n-2];
	t = he->text + he->words[2*n-1];

When the quote is unclosed, t - s == 6 when it should count 5.

> I'm seeing this in 4.2.0 and 4.2.1, not 4.0.6.

Not surprising, as 4.0.6 doesn't have the previous history cycling 
behavior at all.  That was a 4.1.something addition.



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