[git commit] ash: fix handling of negative start value in ${v:start:len}
Denys Vlasenko
vda.linux at googlemail.com
Mon Nov 17 19:27:18 UTC 2014
commit: http://git.busybox.net/busybox/commit/?id=08a5dab181fa4c28b7636c35021308e1e12e7b59
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
function old new delta
subevalvar 1140 1168 +28
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
shell/ash.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/shell/ash.c b/shell/ash.c
index 705fe9f..90fb00f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6411,7 +6411,15 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
len = number(loc);
}
}
- if (pos >= orig_len) {
+ if (pos < 0) {
+ /* ${VAR:$((-n)):l} starts n chars from the end */
+ pos = orig_len + pos;
+ }
+ if ((unsigned)pos >= orig_len) {
+ /* apart from obvious ${VAR:999999:l},
+ * covers ${VAR:$((-9999999)):l} - result is ""
+ * (bash-compat)
+ */
pos = 0;
len = 0;
}
More information about the busybox-cvs
mailing list