fix postun in not evaluated side of e.g. ternary operator (LP#1187729)

This commit is contained in:
tg 2013-07-21 18:38:56 +00:00
parent bd795a83ae
commit 3bc3e8665a
2 changed files with 24 additions and 6 deletions

18
check.t
View File

@ -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

12
expr.c
View File

@ -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;