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

Re: completion matching problem with 4.3.8



On Thu, 30 Oct 2008 12:28:50 +0100
Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> There seems to be a problem with matching control.
> 
> touch PacketDefinitionSAXHandler.h PacketListBox.cpp PacketListBox.h PacketsDialog.h
> zsh -f
> autoload -U compinit; compinit
> zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
> : P<tab>
>   --> Completes to 'Packets' instead of just 'Packet'

(Well, took an hour and three quarter or so.)

This *might* be the fix to the original bug.

The valgrind error in pattern_match_restrict() about uninitialised
memory was because at that point the memory is deliberately
uninitialised---we're building up the matched line.  We should therefore
be testing for the case where we're doing that (prestrict != NULL).  If
we get to the end and prestrict is not NULL, we haven't succeeded in
building the line because we haven't fulfilled all the restrictions, so
we should return 0, which is the fix for the bug above, perhaps.

I deliberately left in some debug tests that I added while tracking this
down.  You get file and line number; anything else is superflous here.

Someone should try some hairy matching just to make sure.

Index: Src/Zle/compmatch.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compmatch.c,v
retrieving revision 1.60
diff -u -r1.60 compmatch.c
--- Src/Zle/compmatch.c	30 Oct 2008 20:29:56 -0000	1.60
+++ Src/Zle/compmatch.c	30 Oct 2008 21:54:59 -0000
@@ -156,6 +156,7 @@
     r->next = NULL;
     r->line = l; r->llen = ll;
     r->word = w; r->wlen = wl;
+    DPUTS(wl > 0 && !*w, "Bad word");
     r->orig = o; r->olen = ol;
     r->slen = 0;
     r->flags = fl;
@@ -416,6 +417,7 @@
     } else {
 	lp->line = l; lp->llen = wl;
 	lp->word = w; lp->wlen = wl;
+	DPUTS(wl > 0 && !*w, "Bad word");
 	lp->orig = o; lp->olen = ol;
     }
     if (o || ol)
@@ -1242,7 +1244,7 @@
 
 /*
  * Check if the given pattern matches the given string.
- *  p and  s are either anchor or line pattern and string;
+ * p and  s are either anchor or line pattern and string;
  * wp and ws are word (candidate) pattern and string
  *
  * If only one pattern is given, we just check if characters match.
@@ -1273,7 +1275,7 @@
     int wc, wind;
     int len = 0, wlen, mt, wmt;
 
-    while (p && wp && *s && *ws) {
+    while (p && wp && (prestrict || *s) && *ws) {
 	/* First test the word character */
 	if (*ws == Meta) {
 	    wc = STOUC(ws[1]) ^ 32;
@@ -1387,7 +1389,7 @@
 	wp = wp->next;
     }
 
-    while (p && *s) {
+    while (p && (prestrict || *s)) {
 	if (prestrict) {
 	    /*
 	     * As above, but with even less info to go on.
@@ -1438,6 +1440,11 @@
 	    s += len;
     }
 
+    if (prestrict) {
+	/* Restriction with nothing to match */
+	return 0;
+    }
+
     while (wp && *ws) {
 	/* No funny business when we only have the word pattern. */
 	if (*ws == Meta) {
@@ -2057,6 +2064,7 @@
     } else if (md->len != md->olen) {
 	r->wlen = md->len;
 	r->word = md->str - (sfx ? md->len : 0);
+	DPUTS(r->wlen > 0 && !*r->word, "Bad word");
     }
     return r;
 }


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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