about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Src/glob.c21
-rw-r--r--Test/D02glob.ztst6
3 files changed, 24 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 3b4893476..2e6dd5118 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-03-16  Peter Stephenson  <pws@csr.com>
+
+	* 20983: Test/D02glob.ztst, Src/glob.c: fixed string segments
+	in globbed paths could be copied wrongly, resulting in failed globs.
+
 2005-03-15  Peter Stephenson  <pws@csr.com>
 
 	* 20978: Src/zle_main.c: don't propagate EOFs from recursive
diff --git a/Src/glob.c b/Src/glob.c
index c1f2fc0dc..5334f70fa 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -223,13 +223,14 @@ struct complist {
 
 /**/
 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 @@ scanner(Complist q)
 		    }
 		}
 		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 @@ scanner(Complist q)
 	    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 */
diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst
index f35e5eb75..e423176a3 100644
--- a/Test/D02glob.ztst
+++ b/Test/D02glob.ztst
@@ -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