summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--Src/exec.c9
-rw-r--r--Test/A04redirect.ztst11
3 files changed, 26 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4c3351517..6f2a0e4f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-03-10 Peter Stephenson <p.w.stephenson@ntlworld.com>
+
+ * 31141: Src/exec.c, Test/A04redirect.ztst: NO_CLOBBER for {fd}
+ syntax should only apply if $fd is exactly an fd and nothing
+ else.
+
2013-03-10 Mikael Magnusson <mikachu@gmail.com>
* 30496: Src/prompt.c: Parse argument to %F and %K as prompt
@@ -577,5 +583,5 @@
*****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5816 $
+* $Revision: 1.5817 $
*****************************************************
diff --git a/Src/exec.c b/Src/exec.c
index 1ecbc3967..fa148756b 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -1885,7 +1885,14 @@ checkclobberparam(struct redir *f)
return 0;
}
- if (!isset(CLOBBER) && (fd = (int)getintvalue(v)) &&
+ /*
+ * We can't clobber the value in the parameter if it's
+ * already an opened file descriptor --- that means it's a decimal
+ * integer corresponding to an opened file descriptor,
+ * not merely an expression that evaluates to a file descriptor.
+ */
+ if (!isset(CLOBBER) && (s = getstrvalue(v)) &&
+ (fd = (int)zstrtol(s, &s, 10)) >= 0 && !*s &&
fd <= max_zsh_fd && fdtable[fd] == FDT_EXTERNAL) {
zwarn("can't clobber parameter %s containing file descriptor %d",
f->varid, fd);
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index b8086e724..7ad02db3b 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -328,6 +328,17 @@
1q:NO_CLOBBER prevents overwriting parameter with allocated fd
?(eval):4: can't clobber parameter myfd containing file descriptor $myfd
+ (setopt noclobber
+ exec {myfd}>logfile2b
+ print First open >&$myfd
+ rm -f logfile2b # prevent normal file no_clobberation
+ myotherfd="${myfd}+0"
+ exec {myotherfd}>logfile2b
+ print Overwritten >&$myotherfd)
+ cat logfile2b
+0:NO_CLOBBER doesn't complain about any other expression
+>Overwritten
+
(exec {myfd}>logfile4
echo $myfd
exec {myfd}>&-