aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-06 19:48:20 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-06 19:48:20 +0200
commit5dad7bdc3bdad8e9934d45301d5a8c51e843cd7b (patch)
treedb493d6ca6cabddcfe3e9a58f33ee712bd1584d4 /shell/hush.c
parent3234045d07c3fb2a9ef8afd02f821158317adbd3 (diff)
downloadbusybox-w32-5dad7bdc3bdad8e9934d45301d5a8c51e843cd7b.tar.gz
busybox-w32-5dad7bdc3bdad8e9934d45301d5a8c51e843cd7b.tar.bz2
busybox-w32-5dad7bdc3bdad8e9934d45301d5a8c51e843cd7b.zip
hush: implement negative start in the ${v: -n[:m]} idiom
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 64b33cf1c..f6b50dec6 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -5619,8 +5619,12 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
5619 goto arith_err; 5619 goto arith_err;
5620 debug_printf_varexp("len:'%s'=%lld\n", exp_word, (long long)len); 5620 debug_printf_varexp("len:'%s'=%lld\n", exp_word, (long long)len);
5621 if (len >= 0) { /* bash compat: len < 0 is illegal */ 5621 if (len >= 0) { /* bash compat: len < 0 is illegal */
5622 if (beg < 0) /* bash compat */ 5622 if (beg < 0) {
5623 beg = 0; 5623 /* negative beg counts from the end */
5624 beg = (arith_t)strlen(val) + beg;
5625 if (beg < 0) /* ${v: -999999} is "" */
5626 beg = len = 0;
5627 }
5624 debug_printf_varexp("from val:'%s'\n", val); 5628 debug_printf_varexp("from val:'%s'\n", val);
5625 if (len == 0 || !val || beg >= strlen(val)) { 5629 if (len == 0 || !val || beg >= strlen(val)) {
5626 arith_err: 5630 arith_err: