fix lazy evaluation of assignments in ternary ops

This commit is contained in:
tg 2009-10-04 13:19:33 +00:00
parent 5f58261287
commit 73147a7fe9
3 changed files with 11 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.318 2009/10/04 12:45:21 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.319 2009/10/04 13:19:32 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 $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R39 2009/10/02
@(#)MIRBSD KSH R39 2009/10/04
description:
Check version of shell.
stdin:
@ -224,7 +224,6 @@ name: arith-lazy-3
description:
Check that assignments not done on non-evaluated side of ternary
operator and this construct is parsed correctly (Debian #445651)
expected-fail: yes
stdin:
x=4
y=$((0 ? x=1 : 2))

12
expr.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.36 2009/09/26 04:01:32 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.37 2009/10/04 13:19:33 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -465,10 +465,12 @@ evalexpr(Expr_state *es, int prec)
}
if (IS_ASSIGNOP(op)) {
stvui(vr, res);
if (vasn->flag & INTEGER)
setint_v(vasn, vr, es->arith);
else
setint(vasn, res);
if (!es->noassign) {
if (vasn->flag & INTEGER)
setint_v(vasn, vr, es->arith);
else
setint(vasn, res);
}
vl = vr;
} else if (op != O_TERN)
stvui(vl, res);

4
sh.h
View File

@ -134,9 +134,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.352 2009/10/02 18:08:36 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.353 2009/10/04 13:19:33 tg Exp $");
#endif
#define MKSH_VERSION "R39 2009/10/02"
#define MKSH_VERSION "R39 2009/10/04"
#ifndef MKSH_INCLUDES_ONLY