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

Re: segfault in completion when using alias with \ as last character



On Aug 1,  9:25am, Bart Schaefer wrote:
}
} On Aug 1,  4:45pm, torstenschmits@xxxxxxxxx wrote:
} }
} } alias foo='bar\'
} } foo <tab>
} } -> segfault.
} 
} Src/Zle/zle_tricky.c:668: BUG: 0 <= wb <= zlemetacs <= we is not true!

The problem appears to be somewhere in the lexer, rather than in the
completion system itself.  Tracing through this, if I use e.g.:

% alias foo='echo'
% foo <TAB>

then in lex.c:gotword() the value of wordbeg is 1, and wb is correctly
calculated.

With foo='bar\', however, wordbeg is 6 so wb ends up negative, and it's
all downhill from there.

The upshot seems to be that the trailing backslash in the expanded
alias causes the space after "foo" on the command line to be consumed
as part of the command word.  In effect, the completion system thinks
the completion is at the beginning of the second word, but the lexer
says no, completion is actually in the middle of the first word, and
docomplete() isn't prepared to deal with that dissonance.

This is handled for history by simply expanding it in place and then
refusing to complete anything if the command line changed, but in the
case of aliases we try try to complete as if the alias were expanded
without actually altering the command line to reveal it.

You can see that the segfault does not happen if there are TWO spaces:

% alias foo='bar\'
% foo  <TAB>
Completing file
Src/               Doc/               config.modules     Config/          
Test/              Makefile           config.modules.sh  Etc/             
config.log         stamp-h            config.status*     config.h         

It seems wrong for gotword() to report wb < 0, but just asserting that
wb = 0 when it computes less than zero still triggers the BUG: warning
(though it correctly causes completion to find no matches and instead
e.g. attempt correction), so there must be other tweaking needed to
get wb, we, zlemetall, and zlemetacs all set properly in this case.



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