[git commit] ash: remove arithmetic expansion collapsing at parse time
Denys Vlasenko
vda.linux at googlemail.com
Mon May 18 07:56:16 UTC 2015
commit: http://git.busybox.net/busybox/commit/?id=ad88bdee0c382b9f1cbbb2d76cc739afb2790a60
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
Collapsing arithmetic expansion is incorrect when the inner arithmetic
expansion is a part of a parameter expansion.
Test case:
unset a
echo $((3 + ${a:=$((4 + 5))}))
echo $a
Old result:
12
(4 + 5)
New result:
12
9
Based on commit bb777a6 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu
function old new delta
readtoken1 3180 3163 -17
Signed-off-by: Ron Yorston <rmy at pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
shell/ash.c | 18 ++++++------------
...llapse-arithmetic-expansion-at-parse-time.right | 2 ++
...llapse-arithmetic-expansion-at-parse-time.tests | 3 +++
3 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/shell/ash.c b/shell/ash.c
index ee7642a..33a477d 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -11316,9 +11316,9 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
parenlevel--;
} else {
if (pgetc() == ')') {
+ c = CTLENDARI;
if (--arinest == 0) {
syntax = prevsyntax;
- c = CTLENDARI;
}
} else {
/*
@@ -11809,18 +11809,12 @@ parsearith: {
if (++arinest == 1) {
prevsyntax = syntax;
syntax = ARISYNTAX;
- USTPUTC(CTLARI, out);
- if (dblquote)
- USTPUTC('"', out);
- else
- USTPUTC(' ', out);
- } else {
- /*
- * we collapse embedded arithmetic expansion to
- * parenthesis, which should be equivalent
- */
- USTPUTC('(', out);
}
+ USTPUTC(CTLARI, out);
+ if (dblquote)
+ USTPUTC('"', out);
+ else
+ USTPUTC(' ', out);
goto parsearith_return;
}
#endif
diff --git a/shell/ash_test/ash-vars/var-do-not-collapse-arithmetic-expansion-at-parse-time.right b/shell/ash_test/ash-vars/var-do-not-collapse-arithmetic-expansion-at-parse-time.right
new file mode 100644
index 0000000..81a1585
--- /dev/null
+++ b/shell/ash_test/ash-vars/var-do-not-collapse-arithmetic-expansion-at-parse-time.right
@@ -0,0 +1,2 @@
+12
+9
diff --git a/shell/ash_test/ash-vars/var-do-not-collapse-arithmetic-expansion-at-parse-time.tests b/shell/ash_test/ash-vars/var-do-not-collapse-arithmetic-expansion-at-parse-time.tests
new file mode 100755
index 0000000..e97a08a
--- /dev/null
+++ b/shell/ash_test/ash-vars/var-do-not-collapse-arithmetic-expansion-at-parse-time.tests
@@ -0,0 +1,3 @@
+unset a
+echo $((3 + ${a:=$((4 + 5))}))
+echo $a
More information about the busybox-cvs
mailing list