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

Re: PATCH: Re: Very odd behaviour with zsh, maybe corruption bug



Bart Schaefer wrote:

> On Oct 12,  5:02am, Bart Schaefer wrote:
> }
> } This *must* be a bug in prefork() called via singsub(); it must be zeroing
> } `right' (and thus also zeroing `opat') before copying the string.  But I
> } just can't seem to catch it happening.
> 
> Having traced through this more closely, which was rather laborious, I
> have come to the conclusion that the bug is right there in evalcond(),
> and that the following is the fix.  At least, I can't see how this patch
> could possibly cause -incorrect- behavior, though it might result in an
> optimization being skipped unnecessarily in some cases.
> 
> Sven, please dispute this if you can.
> 
> ...
>  
> -		right = opat = dupstring(ecrawstr(state->prog, state->pc,
> +		right = dupstring(opat = ecrawstr(state->prog, state->pc,
>  						  &htok));

This is right. I hadn't realised that paramsubst() (called indirectly
from singsub()) modifies the string it gets even though it gets a
pointer (it's that `*s++ = '\0', I think).

We need a similar fix in execcase(), below is a patch for both of
these, which I will commit to both branches.


Bye
  Sven

Index: Src/cond.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/cond.c,v
retrieving revision 1.2
diff -u -r1.2 cond.c
--- Src/cond.c	2000/04/01 20:49:48	1.2
+++ Src/cond.c	2001/10/15 11:23:26
@@ -202,7 +202,7 @@
 		char *opat;
 		int save;
 
-		right = opat = dupstring(ecrawstr(state->prog, state->pc,
+		right = dupstring(opat = ecrawstr(state->prog, state->pc,
 						  &htok));
 		if (htok)
 		    singsub(&right);
Index: Src/loop.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/loop.c,v
retrieving revision 1.5
diff -u -r1.5 loop.c
--- Src/loop.c	2001/06/25 16:07:52	1.5
+++ Src/loop.c	2001/10/15 11:23:26
@@ -543,7 +543,7 @@
 	if (isset(XTRACE)) {
 	    char *pat2, *opat;
 
-	    opat = pat = ecgetstr(state, EC_DUP, NULL);
+	    pat = dupstring(opat = ecrawstr(state->prog, state->pc, NULL));
 	    singsub(&pat);
 	    save = (!(state->prog->flags & EF_HEAP) &&
 		    !strcmp(pat, opat) && *spprog != dummy_patprog2);
@@ -565,7 +565,7 @@
 		char *opat;
 		int htok = 0;
 
-		opat = pat = dupstring(ecrawstr(state->prog,
+		pat = dupstring(opat = ecrawstr(state->prog,
 						state->pc - 2, &htok));
 		if (htok)
 		    singsub(&pat);

-- 
Sven Wischnowsky                    wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author