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

Re: Globbing for directory names with two '='-s fail after 4.2.2.



Kobayashi Noritada wrote:
> Hi,
> 
> Globbing for directory names with two '='-s sometimes fails
> (i.e. wildcards '*' and '?' don't work) with Zsh after 4.2.2.
> It seems to be related to changes in Src/{glob.c,pattern.c} on 2004-10-18.

Thanks for noticing.  Could you try the following patch and see if it
fixes all the problems you are seeing?

The problem was that a string was no longer null-terminated in the case
that it was examined by the pattern matcher, but found to contain no
patterns.

I will commit this on both branches and some time around (western-style)
Easter we should probably produce 4.2.5.  There may be other patches to
transfer.

Index: Src/glob.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/glob.c,v
retrieving revision 1.38
diff -u -r1.38 glob.c
--- Src/glob.c	10 Jan 2005 17:31:19 -0000	1.38
+++ Src/glob.c	16 Mar 2005 11:12:12 -0000
@@ -223,13 +223,14 @@
 
 /**/
 static void
-addpath(char *s)
+addpath(char *s, int l)
 {
     DPUTS(!pathbuf, "BUG: pathbuf not initialised");
-    while (pathpos + (int) strlen(s) + 1 >= pathbufsz)
+    while (pathpos + l + 1 >= pathbufsz)
 	pathbuf = realloc(pathbuf, pathbufsz *= 2);
-    while ((pathbuf[pathpos++] = *s++));
-    pathbuf[pathpos - 1] = '/';
+    while (l--)
+	pathbuf[pathpos++] = *s++;
+    pathbuf[pathpos++] = '/';
     pathbuf[pathpos] = '\0';
 }
 
@@ -504,14 +505,17 @@
 		    }
 		}
 		if (add) {
-		    addpath(str);
+		    addpath(str, l);
 		    if (!closure || !statfullpath("", NULL, 1))
 			scanner((q->closure) ? q : q->next);
 		    pathbuf[pathpos = oppos] = '\0';
 		}
 	    }
-	} else
+	} else {
+	    if (str[l])
+		str = dupstrpfx(str, l);
 	    insert(str, 0);
+	}
     } else {
 	/* Do pattern matching on current path section. */
 	char *fn = pathbuf[pathbufcwd] ? unmeta(pathbuf + pathbufcwd) : ".";
@@ -608,8 +612,9 @@
 	    int oppos = pathpos;
 
 	    for (fn = subdirs; fn < subdirs+subdirlen; ) {
-		addpath(fn);
-		fn += strlen(fn) + 1;
+		int l = strlen(fn);
+		addpath(fn, l);
+		fn += l + 1;
 		memcpy((char *)&errsfound, fn, sizeof(int));
 		fn += sizeof(int);
 		scanner((q->closure) ? q : q->next);  /* scan next level */
Index: Test/D02glob.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D02glob.ztst,v
retrieving revision 1.8
diff -u -r1.8 D02glob.ztst
--- Test/D02glob.ztst	26 Oct 2004 17:20:29 -0000	1.8
+++ Test/D02glob.ztst	16 Mar 2005 11:12:12 -0000
@@ -317,3 +317,9 @@
  print ${foo%% #:*}
 0:Must-match arguments in complex patterns
 >this string has a
+
+ mkdir glob.tmp/ra=1.0_et=3.5
+ touch glob.tmp/ra=1.0_et=3.5/foo
+ print glob.tmp/ra=1.0_et=3.5/???
+0:Bug with intermediate paths with plain strings but tokenized characters
+>glob.tmp/ra=1.0_et=3.5/foo

-- 
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