about summary refs log tree commit diff
path: root/Src/glob.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-05-31 08:56:23 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-05-31 08:56:23 +0000
commit7bf294f2b8329673ffd0ee55fa2cca872e5448df (patch)
tree0ab313d514fd5dfbeede7a34876df8e921dc2519 /Src/glob.c
parentd5b6d1f40c7dcbc1510e4335924889b55fb648db (diff)
downloadzsh-7bf294f2b8329673ffd0ee55fa2cca872e5448df.tar.gz
zsh-7bf294f2b8329673ffd0ee55fa2cca872e5448df.tar.xz
zsh-7bf294f2b8329673ffd0ee55fa2cca872e5448df.zip
Wayne: pattern.c unitialised var
Zero-length arrays now possible with $array[1,0]
Diffstat (limited to 'Src/glob.c')
-rw-r--r--Src/glob.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/Src/glob.c b/Src/glob.c
index 3e8740fd9..e8e6e4fdf 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -921,8 +921,8 @@ glob(LinkList list, LinkNode np, int nountok)
     Complist q;				/* pattern after parsing         */
     char *ostr = (char *)getdata(np);	/* the pattern before the parser */
 					/* chops it up                   */
-    int first = 0, last = -1;		/* index of first/last match to  */
-				        /* return */
+    int first = 0, count = -1;		/* index of first match to return */
+					/* plus number of items		 */
     struct globdata saved;		/* saved glob state              */
 
     if (unset(GLOBOPT) || !haswilds(ostr)) {
@@ -1334,15 +1334,15 @@ glob(LinkList list, LinkNode np, int nountok)
 
 			    v.isarr = SCANPM_WANTVALS;
 			    v.pm = NULL;
-			    v.b = -1;
+			    v.len = -1;
 			    v.inv = 0;
 			    if (getindex(&s, &v) || s == os) {
 				zerr("invalid subscript", NULL, 0);
 				restore_globstate(saved);
 				return;
 			    }
-			    first = v.a;
-			    last = v.b;
+			    first = v.start;
+			    count = v.len;
 			    break;
 			}
 		    default:
@@ -1428,16 +1428,15 @@ glob(LinkList list, LinkNode np, int nountok)
 
     if (first < 0)
 	first += matchct;
-    if (last < 0)
-	last += matchct;
+    if (count < 0)
+	count += matchct + 1;
     if (first < 0)
 	first = 0;
-    if (last >= matchct)
-	last = matchct - 1;
-    if (first <= last) {
-	matchptr = matchbuf + matchct - 1 - last;
-	last -= first;
-	while (last-- >= 0) {		/* insert matches in the arg list */
+    if (count > matchct - first)
+	count = matchct - first;
+    if (count > 0) {
+	matchptr = matchbuf + matchct - first - count;
+	while (count-- > 0) {		/* insert matches in the arg list */
 	    insertlinknode(list, node, matchptr->name);
 	    matchptr++;
 	}