From 3bc3e8665a14b4f87fe3a63b51319750f20b534d Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 21 Jul 2013 18:38:56 +0000 Subject: [PATCH] fix postun in not evaluated side of e.g. ternary operator (LP#1187729) --- check.t | 18 +++++++++++++++++- expr.c | 12 +++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/check.t b/check.t index c818771..a55e9ea 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.617 2013/07/21 18:35:57 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.618 2013/07/21 18:38:53 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -292,6 +292,22 @@ stdin: expected-stdout: = 4 2 = --- +name: arith-lazy-4 +description: + Check that preun/postun not done on non-evaluated side of ternary + operator +stdin: + (( m = n = 0, 1 ? n++ : m++ ? 2 : 3 )) + echo "($n, $m)" + m=0; echo $(( 0 ? ++m : 2 )); echo $m + m=0; echo $(( 0 ? m++ : 2 )); echo $m +expected-stdout: + (1, 0) + 2 + 0 + 2 + 0 +--- name: arith-ternary-prec-1 description: Check precedence of ternary operator vs assignment diff --git a/expr.c b/expr.c index 6b35ae4..e91c0da 100644 --- a/expr.c +++ b/expr.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.71 2013/05/31 23:27:13 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.72 2013/07/21 18:38:56 tg Exp $"); /* the order of these enums is constrained by the order of opinfo[] */ enum token { @@ -321,10 +321,12 @@ do_ppmm(Expr_state *es, enum token op, struct tbl *vasn, bool is_prefix) ++vl->val.u; else --vl->val.u; - if (vasn->flag & INTEGER) - setint_v(vasn, vl, es->arith); - else - setint(vasn, vl->val.i); + if (!es->noassign) { + if (vasn->flag & INTEGER) + setint_v(vasn, vl, es->arith); + else + setint(vasn, vl->val.i); + } if (!is_prefix) /* undo the increment/decrement */ vl->val.u = oval;