diff options
-rw-r--r-- | shell/hush.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index 179155f66..c970d9097 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -6466,17 +6466,16 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p) /* ${var/[/]pattern[/repl]} helpers */ static char *strstr_pattern(char *val, const char *pattern, int *size) { - if (!strpbrk(pattern, "*?[\\")) { + int sz = strcspn(pattern, "*?[\\"); + if (pattern[sz] == '\0') { /* Optimization for trivial patterns. * Testcase for very slow replace (performs about 22k replaces): * x=:::::::::::::::::::::: * x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;x=$x$x;echo ${#x} * echo "${x//:/|}" */ - char *found = strstr(val, pattern); - if (found) - *size = strlen(pattern); - return found; + *size = sz; + return strstr(val, pattern); } while (1) { |