ash: fix handling of negative start value in ${v:start:len}
function old new delta subevalvar 1140 1168 +28 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
1a1143907c
commit
08a5dab181
10
shell/ash.c
10
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user