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

Re: hzoli change: $foo:s//r/



Another very minor problem with Zoltan's substitution code.

If hsubr is non-NULL, and a "bad/no previous substitution" error 
occurs, hsubr is free()d. This may corrupt memory. Example:

  $ PS1='[%!] ' ./zsh -f
  [1] echo $foo:s/x//
  
  [2] echo $foo:s/ //
  zsh: bad substitution
  [3] echo $foo:s/ //
  zsh: attempt to free already free storage

This fix only free()s hsubr when there was *no* error.

--- zsh-2.6-beta10-hzoli10.3/Src/subst.c.orig	Wed Aug 16 16:15:45 1995
+++ zsh-2.6-beta10-hzoli10.3/Src/subst.c	Wed Aug 16 16:37:07 1995
@@ -1461,5 +1461,4 @@
 		c = **ptr;
 		(*ptr)++;
-		zsfree(hsubr);
 		ptr1 = *ptr;
 		del = *ptr1++;
@@ -1481,4 +1480,5 @@
 		    return;
 		}
+		zsfree(hsubr);
 		for (tt = hsubl; *tt; tt++)
 		    if (INULL(*tt))

-- 
Thorsten Meinecke
<kaefer@xxxxxxxxxxxxxxx>



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