zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh workers <zsh-workers@sunsite.dk>
Subject: Re: completion matching problem with 4.3.8
Date: Thu, 30 Oct 2008 22:00:46 +0000	[thread overview]
Message-ID: <20081030220046.2e94bcfc@pws-pc> (raw)
In-Reply-To: <24068.1225366130@thecus>

On Thu, 30 Oct 2008 12:28:50 +0100
Oliver Kiddle <okiddle@yahoo.co.uk> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  parent reply	other threads:[~2008-10-30 22:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-30 11:28 Oliver Kiddle
2008-10-30 12:17 ` Peter Stephenson
2008-10-30 13:13   ` Oliver Kiddle
2008-10-30 14:11     ` Peter Stephenson
2008-10-30 15:05       ` Oliver Kiddle
2008-10-30 15:43         ` Oliver Kiddle
2008-10-30 20:21           ` Peter Stephenson
2008-10-30 22:00 ` Peter Stephenson [this message]
2008-10-31  9:08   ` Oliver Kiddle

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=20081030220046.2e94bcfc@pws-pc \
    --to=p.w.stephenson@ntlworld.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).