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

Re: crash in tabcompleting



Peter Stephenson wrote:
> Mikael Magnusson wrote:
> > It seems one file is enough. I also failed to mention that zsh doesn't
> > crash if there are any other files in the same directory. It has to be
> > only ones which cause the problem I think. (not sure exactly what that
> > is though).
> > This script succeeds in creating the file for me:
> > 
> > 
> > a='+WSdYWmEb - +WSdZfTBNMF8wmTCIMAI.avi'
> > b="`echo $a|iconv -f utf7 -t utf8`"
> > touch "$b"
> 
> This is good enough for me to see that somewhere the completion system
> is messing up the use of metafied characters: with debugging turned on,
> there's an error message from "ztrsub" because there's a Meta at the end
> of the variable.

It looks like the code to move along compprefix (and compsuffix, though
that didn't seem to show up here) didn't take account of Meta
characters.  I'd guess there's much, much more like this.  This has been
there for ages, but it's liable to show up in different ways.

Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.69
diff -u -r1.69 compcore.c
--- Src/Zle/compcore.c	14 Jan 2005 13:05:22 -0000	1.69
+++ Src/Zle/compcore.c	21 Mar 2005 18:38:44 -0000
@@ -1532,8 +1532,8 @@
 	    untokenize(ss);
 	    compsuffix = ztrdup(ss);
 	}
-        if ((i = strlen(compprefix)) &&
-            compprefix[i - 1] == '\\' && compprefix[i - 2] != '\\')
+        if ((i = strlen(compprefix)) > 1 && compprefix[i - 1] == '\\' &&
+	    compprefix[i - 2] != '\\' && compprefix[i - 2] != Meta)
             compprefix[i - 1] = '\0';
         
 	tmp = tricat(compqiprefix, compiprefix, multiquote(qp, 1));
Index: Src/Zle/complete.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complete.c,v
retrieving revision 1.27
diff -u -r1.27 complete.c
--- Src/Zle/complete.c	7 Dec 2004 16:55:11 -0000	1.27
+++ Src/Zle/complete.c	21 Mar 2005 18:38:44 -0000
@@ -821,18 +821,32 @@
 		    add = -1;
 		} else {
 		    p = compprefix + 1;
+		    if (*p == Meta)
+			p++;
 		    add = 1;
 		}
-		for (; l; l--, p += add) {
+		for (;;) {
 		    sav = *p;
 		    *p = '\0';
 		    test = pattry(pp, compprefix);
 		    *p = sav;
 		    if (test && !--na)
 			break;
+		    if (add > 0) {
+			if (p == compprefix + l)
+			    return 0;
+			if (*p == Meta)
+			    p += 2;
+			else
+			    p++;
+		    } else {
+			if (p == compprefix)
+			    return 0;
+			p--;
+			if (p > compprefix && p[-1] == Meta)
+			    p--;
+		    }
 		}
-		if (!l)
-		    return 0;
 		if (mod)
 		    ignore_prefix(p - compprefix);
 	    } else {
@@ -847,14 +861,30 @@
 		    add = 1;
 		} else {
 		    p = compsuffix + l - 1;
+		    if (p > compsuffix && p[-1] == Meta)
+			p--;
 		    add = -1;
 		}
-		for (; l; l--, p += add)
+		for (;;) {
 		    if (pattry(pp, p) && !--na)
 			break;
 
-		if (!l)
-		    return 0;
+		    if (add > 0) {
+			if (p == compsuffix + l)
+			    return 0;
+			if (*p == Meta)
+			    p += 2;
+			else
+			    p++;
+		    } else {
+			if (p == compsuffix)
+			    return 0;
+			p--;
+			if (p > compsuffix && p[-1] == Meta)
+			    p--;
+		    }
+		}
+
 		if (mod)
 		    ignore_suffix(ol - (p - compsuffix));
 	    }

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


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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