From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3026 invoked by alias); 2 Aug 2013 05:49:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31628 Received: (qmail 26323 invoked from network); 2 Aug 2013 05:49:18 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130801224901.ZM10731@torch.brasslantern.com> Date: Thu, 01 Aug 2013 22:49:01 -0700 In-reply-to: <130801092508.ZM8575@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: segfault in completion when using alias with \ as last character" (Aug 1, 9:25am) References: <20130801144552.GA11716@gluon.atom> <130801092508.ZM8575@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: segfault in completion when using alias with \ as last character MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Aug 1, 9:25am, Bart Schaefer wrote: } } On Aug 1, 4:45pm, torstenschmits@gmail.com wrote: } } } } alias foo='bar\' } } foo } } -> 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 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 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.