diff mbox

[v2] don't record empty IFS scan regions

Message ID f414f145-1ed9-91df-b98c-90ef0e302118@inlv.org (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Martijn Dekker March 22, 2018, 10:20 a.m. UTC
evalvar() records empty expansion results (varlen == 0) as string
regions that need to be scanned for IFS characters. This is pointless,
because there is nothing to split.

This patch fixes the following bug, which is apparently a side effect of
the above:

$ dash -c 'IFS=; set --
        set -- $@ $*; printf $#,
        set -- $@ $*; printf $#,
        set -- $@ $*; echo $#'
2,4,8

Expected output: 0,0,0. Given set & empty IFS and no positional
parameters, unquoted $@ and $* incorrectly generate one empty field
(they should generate no fields).

- M.
diff mbox

Patch

diff --git a/src/expand.c b/src/expand.c
index 705fef7..03a9b0c 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -771,7 +771,7 @@  vsplus:
 
 	if (subtype == VSNORMAL) {
 record:
-		if (!easy)
+		if (!easy || varlen == 0)
 			goto end;
 		recordregion(startloc, expdest - (char *)stackblock(), quoted);
 		goto end;