From f77a7a5b18f0650d32e5e8dac1f1cb284a9e4690 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 7 Nov 2013 15:19:07 +0000 Subject: 31937: zle -Fw uses widget semantics for file descriptor handler --- Src/math.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'Src/math.c') 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); } -- cgit 1.4.1