about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/expn.yo7
-rw-r--r--Src/subst.c26
3 files changed, 31 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 7eac6ca79..5baaa2130 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,13 @@
 	Completion/Unix/Commands/_ip (tweaked), Doc/Zsh/compsys.yo: add to
 	regex completion handling and add new ip completion.
 
+2007-02-25  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* 23176 (tweaked): Doc/Zsh/expn.yo, Src/subst.c: make the (X)
+	parameter expansion flag apply to the (#) flag as well, so that
+	"character not in range" is not normally a fatal error.  Also
+	fix a minor typo in a comment.
+
 2007-02-25  Clint Adams  <clint@zsh.org>
 
 	* 23185: Tobias Gruetzmacher: Completion/Unix/Command/_qemu: qemu
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index c18a297ad..df95ccef2 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -874,9 +874,10 @@ Similar to tt(w) with the difference that empty words between
 repeated delimiters are also counted.
 )
 item(tt(X))(
-With this flag parsing errors occurring with the tt(Q) and tt(e) flags or the
-pattern matching forms such as `tt(${)var(name)tt(#)var(pattern)tt(})' 
-are reported. Without the flag they are silently ignored.
+With this flag, parsing errors occurring with the tt(Q), tt(e) and tt(#)
+flags or the pattern matching forms such as
+`tt(${)var(name)tt(#)var(pattern)tt(})' are reported.  Without the flag,
+errors are silently ignored.
 )
 item(tt(z))(
 Split the result of the expansion into words using shell parsing to
diff --git a/Src/subst.c b/Src/subst.c
index acd121e78..9d6a41305 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1193,7 +1193,7 @@ static char *
 substevalchar(char *ptr)
 {
     zlong ires = mathevali(ptr);
-    int len;
+    int len = 0;
 
     if (errflag)
 	return NULL;
@@ -1204,7 +1204,8 @@ substevalchar(char *ptr)
 	/* inefficient: should separate out \U handling from getkeystring */
 	sprintf(buf, "\\U%.8x", (unsigned int)ires);
 	ptr = getkeystring(buf, &len, GETKEYS_BINDKEY, NULL);
-    } else
+    }
+    if (len == 0)
 #endif
     {
 	ptr = zhalloc(2);
@@ -2603,7 +2604,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 	/*
 	 * Handler ${+...}.  TODO: strange, why do we handle this only
 	 * if there isn't a trailing modifier?  Why don't we do this
-	 * e.g. when we hanlder the ${(t)...} flag?
+	 * e.g. when we handle the ${(t)...} flag?
 	 */
 	if (chkset) {
 	    val = dupstring(vunset ? "0" : "1");
@@ -2658,6 +2659,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
     if (errflag)
 	return NULL;
     if (evalchar) {
+	int one = noerrs, oef = errflag, haserr = 0;
+
+	if (!quoteerr)
+	    noerrs = 1;
 	/*
 	 * Evaluate the value numerically and output the result as
 	 * a character.
@@ -2669,15 +2674,24 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 
 	    for (avptr = aval, av2ptr = aval2; *avptr; avptr++, av2ptr++)
 	    {
-		if (!(*av2ptr = substevalchar(*avptr)))
-		    return NULL;
+		/* When noerrs = 1, the only error is out-of-memory */
+		if (!(*av2ptr = substevalchar(*avptr))) {
+		    haserr = 1;
+		    break;
+		}
 	    }
 	    *av2ptr = NULL;
 	    aval = aval2;
 	} else {
+	    /* When noerrs = 1, the only error is out-of-memory */
 	    if (!(val = substevalchar(val)))
-		return NULL;
+		haserr = 1;
 	}
+	noerrs = one;
+	if (!quoteerr)
+	    errflag = oef;
+	if (haserr || errflag)
+	    return NULL;
     }
     /*
      * This handles taking a length with ${#foo} and variations.