[git commit] ash: match bash behavior for ${empty_var/*/repl}

Denys Vlasenko vda.linux at googlemail.com
Sat Jan 9 07:46:54 UTC 2021


commit: https://git.busybox.net/busybox/commit/?id=2b7c1aa92c68524559a2067609d09309d5c09adc
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 shell/ash.c                                           | 6 +++---
 shell/ash_test/ash-vars/var_bash_repl_empty_var.right | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 76bf39ec2..1aead6df4 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7178,7 +7178,7 @@ subevalvar(char *start, char *str, int strloc,
 		len = 0;
 		idx = startp;
 		end = str - 1;
-		while (idx < end) {
+		while (idx <= end) {
  try_to_match:
 			loc = scanright(idx, rmesc, rmescend, str, quotes, 1);
 			//bb_error_msg("scanright('%s'):'%s'", str, loc);
@@ -7186,6 +7186,8 @@ subevalvar(char *start, char *str, int strloc,
 				/* No match, advance */
 				char *restart_detect = stackblock();
  skip_matching:
+				if (idx >= end)
+					break;
 				STPUTC(*idx, expdest);
 				if (quotes && (unsigned char)*idx == CTLESC) {
 					idx++;
@@ -7198,8 +7200,6 @@ subevalvar(char *start, char *str, int strloc,
 				len++;
 				rmesc++;
 				/* continue; - prone to quadratic behavior, smarter code: */
-				if (idx >= end)
-					break;
 				if (str[0] == '*') {
 					/* Pattern is "*foo". If "*foo" does not match "long_string",
 					 * it would never match "ong_string" etc, no point in trying.
diff --git a/shell/ash_test/ash-vars/var_bash_repl_empty_var.right b/shell/ash_test/ash-vars/var_bash_repl_empty_var.right
index cf8f088c1..a8d1a3bef 100644
--- a/shell/ash_test/ash-vars/var_bash_repl_empty_var.right
+++ b/shell/ash_test/ash-vars/var_bash_repl_empty_var.right
@@ -1,3 +1,3 @@
 
-
+w
 Ok:0


More information about the busybox-cvs mailing list