about summary refs log tree commit diff
path: root/Src/math.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2013-11-07 15:19:07 +0000
committerPeter Stephenson <pws@zsh.org>2013-11-07 15:19:07 +0000
commitf77a7a5b18f0650d32e5e8dac1f1cb284a9e4690 (patch)
tree2cfeba444292386f17afa88237ceeaf20c1fdf67 /Src/math.c
parent375115c7dfd6dff576915d25fe2ecdd381dd9d81 (diff)
downloadzsh-f77a7a5b18f0650d32e5e8dac1f1cb284a9e4690.tar.gz
zsh-f77a7a5b18f0650d32e5e8dac1f1cb284a9e4690.tar.xz
zsh-f77a7a5b18f0650d32e5e8dac1f1cb284a9e4690.zip
31937: zle -Fw uses widget semantics for file descriptor handler
Diffstat (limited to 'Src/math.c')
-rw-r--r--Src/math.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/Src/math.c b/Src/math.c
index eae283d19..b21a3adee 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -1374,6 +1374,19 @@ mathevalarg(char *s, char **ss)
     mnumber x;
     int xmtok = mtok;
 
+    /*
+     * At this entry point we don't allow an empty expression,
+     * whereas we do with matheval().  I'm not sure if this
+     * difference is deliberate, but it does mean that e.g.
+     * $array[$ind] where ind hasn't been set produces an error,
+     * which is probably safe.
+     *
+     * To avoid a more opaque error further in, bail out here.
+     */
+    if (!*s) {
+	zerr("bad math expression: empty string");
+	return (zlong)0;
+    }
     x = mathevall(s, MPREC_ARG, ss);
     if (mtok == COMMA)
 	(*ss)--;
@@ -1401,6 +1414,7 @@ checkunary(int mtokc, char *mptr)
     }
     if (errmsg) {
 	int len, over = 0;
+	char *errtype = errmsg == 2 ? "operator" : "operand";
 	while (inblank(*mptr))
 	    mptr++;
 	len = ztrlen(mptr);
@@ -1408,9 +1422,12 @@ checkunary(int mtokc, char *mptr)
 	    len = 10;
 	    over = 1;
 	}
-	zerr("bad math expression: %s expected at `%l%s'",
-	     errmsg == 2 ? "operator" : "operand",
-	     mptr, len, over ? "..." : "");
+	if (!*mptr)
+	    zerr("bad math expression: %s expected at end of string",
+		errtype);
+	else
+	    zerr("bad math expression: %s expected at `%l%s'",
+		 errtype, mptr, len, over ? "..." : "");
     }
     unary = !(tp & OP_OPF);
 }