zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list),
	Mikael Magnusson <mikachu@gmail.com>
Subject: Re: crash in tabcompleting
Date: Mon, 21 Mar 2005 18:42:46 +0000	[thread overview]
Message-ID: <200503211842.j2LIglgU008339@news01.csr.com> (raw)
In-Reply-To: <200503211712.j2LHCMjW015774@news01.csr.com>

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@csr.com>                  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.

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


      reply	other threads:[~2005-03-21 18:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-21  1:57 Mikael Magnusson
2005-03-21 11:06 ` Peter Stephenson
     [not found]   ` <237967ef05032104425384f32b@mail.gmail.com>
2005-03-21 17:12     ` Peter Stephenson
2005-03-21 18:42       ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200503211842.j2LIglgU008339@news01.csr.com \
    --to=pws@csr.com \
    --cc=mikachu@gmail.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).