From 75e01cb3050aef68b0ec2b0ec7014910c7e426f8 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 22 Mar 2009 17:58:58 +0000 Subject: [PATCH] Revision 1.18: [7]download - view: [8]text, [9]markup, [10]annotated - [11]select for diffs Sun Mar 1 20:11:06 2009 UTC (2 weeks, 6 days ago) by otto Branches: [12]MAIN CVS tags: [13]HEAD Diff to: previous 1.17: [14]preferred, [15]coloured Changes since revision 1.17: +17 -9 lines Fix PR #[16]723: [17]test(1) operator precedence inconsistent with POSIX Make sure ksh builtin test and [18]test(1) do not differ. From Christiano Farina Haesbaert. ok miod@ --- funcs.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/funcs.c b/funcs.c index 6271fa0..560eda6 100644 --- a/funcs.c +++ b/funcs.c @@ -1,11 +1,11 @@ /* $OpenBSD: c_ksh.c,v 1.33 2009/02/07 14:03:24 kili Exp $ */ /* $OpenBSD: c_sh.c,v 1.39 2009/01/29 23:27:26 jaredy Exp $ */ -/* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */ +/* $OpenBSD: c_test.c,v 1.18 2009/03/01 20:11:06 otto Exp $ */ /* $OpenBSD: c_ulimit.c,v 1.17 2008/03/21 12:51:19 millert Exp $ */ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.98 2009/03/22 17:53:50 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.99 2009/03/22 17:58:58 tg Exp $"); /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -2762,15 +2762,22 @@ test_primary(Test_env *te, bool do_eval) } return rv; } - if ((op = (*te->isa)(te, TM_UNOP))) { - /* unary expression */ - opnd1 = (*te->getopnd)(te, op, do_eval); - if (!opnd1) { - (*te->error)(te, -1, "missing argument"); - return 0; - } + /* + * Binary should have precedence over unary in this case + * so that something like test \( -f = -f \) is accepted + */ + if ((te->flags & TEF_DBRACKET) || (&te->pos.wp[1] < te->wp_end && + !test_isop(te, TM_BINOP, te->pos.wp[1]))) { + if ((op = (*te->isa)(te, TM_UNOP))) { + /* unary expression */ + opnd1 = (*te->getopnd)(te, op, do_eval); + if (!opnd1) { + (*te->error)(te, -1, "missing argument"); + return 0; + } - return (*te->eval)(te, op, opnd1, NULL, do_eval); + return (*te->eval)(te, op, opnd1, NULL, do_eval); + } } opnd1 = (*te->getopnd)(te, TO_NONOP, do_eval); if (!opnd1) {