zsh-workers
 help / color / mirror / code / Atom feed
* Bugs with exclusion using file paths.
@ 2000-03-26 22:17 Peter Stephenson
  2000-03-29 17:19 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2000-03-26 22:17 UTC (permalink / raw)
  To: Zsh hackers list

Fixes for the bugs I mentioned earlier.  For globbing, a top level ~
is handled specially, leading to these two.  Getting exclusion to work
properly is extremely complicated, so I can't promise this is the last of
it.  Maybe someone out there knows better algorithms.


1. Some idiot messed up the exclusion of absolute paths when he was optimizing
the pattern matching code.

5:32% print /*
/bin /boot /data /dev /etc /home /lib /lost+found /mnt /opt /proc /root /sbin /tmp /usr /var /windows
5:32% print /*~/b*
/*~/b*

The problem is that / is treated as an end of path segment, which it isn't
in the exclusion part, so it first parses /*~ as a string, then finds
garbage at the end.


2. print **/*~(.)# dumped core

This is because the pattern is handled in two parts.  The path before the
last slash is tried first, then the final bit is matched against whatever's
in the directory.  However, the exclusion is supposed to exclude the entire
pattern, treating / as an ordinary character.  Hence the pre-path has to be
prepended for the exclusion matching only.  I forgot to do this with the
pointer to the start of the pattern, so pointer arithmetic was off.  I
didn't fix up the variable holding the total length of the pattern, either.
This is all a recipe for disaster, and I love to know how else to do it.

We need some real globbing tests to pick up this sort of thing; pattern
matching in tests is insensitive to it.


Index: Src/pattern.c
===================================================================
RCS file: /home/pws/CVSROOT/projects/zsh/Src/pattern.c,v
retrieving revision 1.6
diff -u -r1.6 pattern.c
--- Src/pattern.c	2000/02/23 18:29:27	1.6
+++ Src/pattern.c	2000/03/26 22:05:05
@@ -486,7 +486,8 @@
 
     while (*patparse == Bar ||
 	   (isset(EXTENDEDGLOB) && *patparse == Tilde &&
-	    !memchr(patendseg, patparse[1], patendseglen))) {
+	    (patparse[1] == '/' ||
+	     !memchr(patendseg, patparse[1], patendseglen)))) {
 	int tilde = *patparse++ == Tilde;
 	long gfnode = 0, newbr;
 
@@ -634,7 +635,7 @@
 
     starter = chain = 0;
     while (!memchr(patendseg, *patparse, patendseglen) ||
-	   (*patparse == Tilde &&
+	   (*patparse == Tilde && patparse[1] != '/' &&
 	    memchr(patendseg, patparse[1], patendseglen))) {
 	if (isset(EXTENDEDGLOB) &&
 	    ((!isset(SHGLOB) &&
@@ -811,6 +812,7 @@
 	 */
 	if (kshchar || (memchr(patendstr, *patparse, patendstrlen) &&
 			(*patparse != Tilde ||
+			 patparse[1] == '/' ||
 			 !memchr(patendseg, patparse[1], patendseglen))))
 	    break;
 
@@ -1754,7 +1756,8 @@
 			while ((ret = patmatch(P_OPERAND(scan)))) {
 			    unsigned char *syncpt;
 			    char savchar, *testptr;
-			    int savforce = forceerrs;
+			    char *savpatinstart = patinstart;
+			    int savforce = forceerrs, savpatinlen = patinlen;
 			    forceerrs = -1;
 			    savglobdots = globdots;
 			    matchederrs = errsfound;
@@ -1799,7 +1802,8 @@
 					zalloc(pathpos + patinlen);
 				    strcpy(buf, pathbuf);
 				    strcpy(buf + pathpos, patinput);
-				    patinput = buf;
+				    patinput = patinstart = buf;
+				    patinlen += pathpos;
 				}
 				if (patmatch(opnd)) {
 				    ret = 0;
@@ -1810,8 +1814,11 @@
 				     */
 				    parsfound = savparsfound;
 				}
-				if (buf)
+				if (buf) {
 				    zfree(buf, pathpos + patinlen);
+				    patinstart = savpatinstart;
+				    patinlen = savpatinlen;
+				}
 				if (!ret)
 				    break;
 				next = PATNEXT(next);

-- 
Peter Stephenson <pws@pwstephenson.fsnet.co.uk>


^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: Bugs with exclusion using file paths.
@ 2000-03-29  8:26 Sven Wischnowsky
  2000-03-28 20:48 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2000-03-29  8:26 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> ...
> @@ -1810,8 +1814,11 @@
>  				     */
>  				    parsfound = savparsfound;
>  				}
> -				if (buf)
> +				if (buf) {
>  				    zfree(buf, pathpos + patinlen);
> +				    patinstart = savpatinstart;
> +				    patinlen = savpatinlen;
> +				}
>  				if (!ret)
>  				    break;
>  				next = PATNEXT(next);

With something like **/_*~*~ I now get lots of:

  BUG: attempt to free more than allocated.

warnings. I haven't grokked all this pattern.c stuff, so I can't send
a patch (I don't even know if the problem is just with the second arg
to zfree() or if this shows a real bug).

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-03-29 22:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-26 22:17 Bugs with exclusion using file paths Peter Stephenson
2000-03-29 17:19 ` Bart Schaefer
2000-03-29  8:26 Sven Wischnowsky
2000-03-28 20:48 ` Peter Stephenson
2000-03-29 22:18   ` Bart Schaefer

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