summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-09-05 13:15:30 +0100
committerPeter Stephenson <pws@zsh.org>2017-09-05 13:15:30 +0100
commitea5b38935a17af38a328c8013e7eaf3c8de7ba09 (patch)
treec91701390f945d17ba5c69ad04198d577c88aaeb
parent5a8155f7b7ab8f3cab1f95d4dba5ed49de0ab77c (diff)
downloadzsh-ea5b38935a17af38a328c8013e7eaf3c8de7ba09.tar.gz
zsh-ea5b38935a17af38a328c8013e7eaf3c8de7ba09.zip
41641: Some math operations shouldn't be lvalues.
This includes pre- and post- increment and decrement. Simply mark all values after operations as rvalues.
-rw-r--r--ChangeLog5
-rw-r--r--Src/math.c10
-rw-r--r--Test/C01arith.ztst13
3 files changed, 20 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index e51e5c47d..ea7a644b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-09-05 Peter Stephenson <p.stephenson@samsung.com>
+
+ * 41641: Src/math.c: more arithmetic operations need to be
+ marked as rvalues, in particular increment and decrement.
+
2017-09-04 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 41633: Src/parse.c: make sure function definitions including
diff --git a/Src/math.c b/Src/math.c
index f9613001a..c3831602b 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -1306,8 +1306,6 @@ op(int what)
spval->type = MN_INTEGER;
} else
spval->u.l = !spval->u.l;
- stack[sp].lval = NULL;
- stack[sp].pval = NULL;
break;
case COMP:
if (spval->type & MN_FLOAT) {
@@ -1315,8 +1313,6 @@ op(int what)
spval->type = MN_INTEGER;
} else
spval->u.l = ~spval->u.l;
- stack[sp].lval = NULL;
- stack[sp].pval = NULL;
break;
case POSTPLUS:
a = *spval;
@@ -1335,16 +1331,12 @@ op(int what)
(void)setmathvar(stack + sp, a);
break;
case UPLUS:
- stack[sp].lval = NULL;
- stack[sp].pval = NULL;
break;
case UMINUS:
if (spval->type & MN_FLOAT)
spval->u.d = -spval->u.d;
else
spval->u.l = -spval->u.l;
- stack[sp].lval = NULL;
- stack[sp].pval = NULL;
break;
case QUEST:
DPUTS(sp < 2, "BUG: math: three shall be the number of the counting.");
@@ -1377,6 +1369,8 @@ op(int what)
zerr("bad math expression: out of integers");
return;
}
+ stack[sp].lval = NULL;
+ stack[sp].pval = NULL;
}
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 61da763ac..30409adf3 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -420,3 +420,16 @@
0:type of variable when created in arithmetic context
>integer
>scalar
+
+ integer a=1
+ print $(( ++a * 2 ))
+ print $(( ++a ))
+ print $(( a++ * 2 ))
+ print $(( a ))
+ print $(( ++a++ * 2 ))
+1: Allow rvalue but not lvalue operations with result of increment
+>4
+>3
+>6
+>4
+?(eval):6: bad math expression: lvalue required