about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2010-02-19 12:45:35 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2010-02-19 12:45:35 +0000
commited5d0535140693dbfa3f0e6d8bf844dfc2d4943b (patch)
tree45d2421837fc771ecc43d94e637670bffbb2e096
parentbbc88550db62ffe2cbdecd62c21252a941f8db36 (diff)
downloadzsh-ed5d0535140693dbfa3f0e6d8bf844dfc2d4943b.tar.gz
zsh-ed5d0535140693dbfa3f0e6d8bf844dfc2d4943b.tar.xz
zsh-ed5d0535140693dbfa3f0e6d8bf844dfc2d4943b.zip
27722: bad error reporting and checking in conditions
-rw-r--r--ChangeLog6
-rw-r--r--Src/cond.c21
-rw-r--r--Test/C02cond.ztst8
-rw-r--r--Test/V01zmodload.ztst2
4 files changed, 28 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 41a4ecc2d..74948d827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2010-02-19  Peter Stephenson  <pws@csr.com>
 
+	* 27722: Src/cond.c, Test/C02cond.zts, Test/V01zmodload.ztst: Error
+	reporting for failed conditions was badly handled; one
+	piece of code didn't test for a '-' prefix.
+
 	* 27723: Src/builtin.c, Test/D02glob.ztst: eval shouldn't
 	modify non-zero return statuses.
 
@@ -12779,5 +12783,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4906 $
+* $Revision: 1.4907 $
 *****************************************************
diff --git a/Src/cond.c b/Src/cond.c
index 2d073fc46..b911bfb33 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -104,7 +104,7 @@ evalcond(Estate state, char *fromtest)
     case COND_MODI:
 	{
 	    Conddef cd;
-	    char *name = overridename;
+	    char *name = overridename, *errname;
 	    char **strs;
 	    int l = WC_COND_SKIP(code);
 
@@ -122,10 +122,17 @@ evalcond(Estate state, char *fromtest)
 		strs = arrdup(sbuf);
 		l = 2;
 	    }
-	    if ((cd = getconddef((ctype == COND_MODI), name + 1, 1))) {
+	    if (name && name[0] == '-')
+		errname = name;
+	    else if (strs[0] && *strs[0] == '-')
+		errname = strs[0];
+	    else
+		errname = "<null>";
+	    if (name && name[0] == '-' &&
+		(cd = getconddef((ctype == COND_MODI), name + 1, 1))) {
 		if (ctype == COND_MOD &&
 		    (l < cd->min || (cd->max >= 0 && l > cd->max))) {
-		    zwarnnam(fromtest, "unknown condition: -%s", name);
+		    zwarnnam(fromtest, "unknown condition: %s", name);
 		    return 2;
 		}
 		if (tracingcond)
@@ -151,8 +158,8 @@ evalcond(Estate state, char *fromtest)
 		if (name && name[0] == '-' &&
 		    (cd = getconddef(0, name + 1, 1))) {
 		    if (l < cd->min || (cd->max >= 0 && l > cd->max)) {
-			zwarnnam(fromtest, "unknown condition: -%s",
-				 name);
+			zwarnnam(fromtest, "unknown condition: %s",
+				 errname);
 			return 2;
 		    }
 		    if (tracingcond)
@@ -160,8 +167,8 @@ evalcond(Estate state, char *fromtest)
 		    return !cd->handler(strs, cd->condid);
 		} else {
 		    zwarnnam(fromtest,
-			     "unknown condition: -%s",
-			     name ? name : "<null>");
+			     "unknown condition: %s",
+			     errname);
 		}
 	    }
 	    /* module not found, error */
diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst
index a824709d3..2d4204038 100644
--- a/Test/C02cond.ztst
+++ b/Test/C02cond.ztst
@@ -285,6 +285,14 @@ F:Failures in these cases do not indicate a problem in the shell.
 0:MATCH, MBEGIN, MEND, match, mbegin, mend
 >OK
 
+  [[ -fail badly ]]
+2:Error message for unknown prefix condition
+?(eval):1: unknown condition: -fail
+
+  [[ really -fail badly ]]
+2:Error message for unknown infix condition
+?(eval):1: unknown condition: -fail
+
 %clean
   # This works around a bug in rm -f in some versions of Cygwin
   chmod 644 unmodish
diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst
index d5e3605ac..25eb81f01 100644
--- a/Test/V01zmodload.ztst
+++ b/Test/V01zmodload.ztst
@@ -151,7 +151,7 @@
   print "Shouldn't get here.")
 2:Failed condition autoload
 ?(eval):3: module `zsh/parameter' has no such feature: `c:fail': autoload cancelled
-?(eval):3: unknown condition: -foo
+?(eval):3: unknown condition: -fail
 
   (zmodload -u zsh/parameter
   zmodload -aF zsh/parameter f:fail