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

Re: _main_complete:343: bad pattern: a[



On Mon, 6 Dec 2010 02:53:44 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 22 November 2009 19:22, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > % zsh -f
> > % autoload -U compinit; compinit
> > % $a[[<tab>
> > _main_complete:343: bad pattern: a[
> 
> There are lots of places in the code that say "bad pattern:", after
> adding identifiers to all of them, I found it's this one in glob.c
> 
>     if (!q || errflag) {	/* if parsing failed */
> 	restore_globstate(saved);
> 	if (unset(BADPATTERN)) {
> 	    if (!nountok)
> 		untokenize(ostr);
> 	    insertlinknode(list, node, ostr);
> 	    return;
> 	}
> 	errflag = 0;
>         /* $a[[<tab> */
> 	zerr("bad pattern: %s", ostr);
> 	return;
>     }
> 
> around line 1730. The real weird thing is that this is triggered by
> _lastcomp=( "${(@kv)compstate}" )
> in _main_complete. Trying to just echo $compstate or variations
> thereof fail in the same way. Now of course I'm curious why anything
> is trying to match a pattern when accessing a variable. Breaking at
> the print shows this backtrace, I realize I have no idea what any of
> these functions are for.

The pattern match is coming from the fact that this is an assignment of
an array, which does globbing.  The globbing should have no effect here
because there shouldn't be any patterns in the assignment.  One of the
values of compstate was therefore letting a token through.  It looks
like it was $compstate[parameter].  Any command line with compstate in
it would similarly look like a failed pattern match.

Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.101
diff -p -u -r1.101 compcore.c
--- Src/Zle/compcore.c	29 Jul 2010 11:08:28 -0000	1.101
+++ Src/Zle/compcore.c	6 Dec 2010 10:44:45 -0000
@@ -648,6 +648,17 @@ callcompfunc(char *s, char *fn)
         else
             compredirs = (char **) zshcalloc(sizeof(char *));
 
+	/*
+	 * We need to untokenize compparameter which is the
+	 * raw internals of a parameter subscript.
+	 *
+	 * The double memory duplication is a bit ugly: the additional
+	 * dupstring() is necessary because untokenize() might change
+	 * the string length and so later zsfree() would get the wrong
+	 * length of the string.
+	 */
+	compparameter = dupstring(compparameter);
+	untokenize(compparameter);
 	compparameter = ztrdup(compparameter);
 	compredirect = ztrdup(compredirect);
 	zsfree(compquote);

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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