Op 22-03-18 om 20:28 schreef Harald van Dijk: > On 22/03/2018 03:40, Martijn Dekker wrote: >> 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. > > varlen may be set to -1 when an unset variable is expanded. If it's > beneficial to avoid recording empty regions to scan for IFS characters, > should those also be excluded? Agreed. Updated patch attached. >> This patch fixes the bug that, given no positional parameters, unquoted >> $@ and $* incorrectly generate one empty field (they should generate no >> fields). Apparently that was a side effect of the above. > > This seems weird though. If you want to remove the recording of empty > regions because they are pointless, then how does removing them fix a > bug? Doesn't this show that empty regions do have an effect? Perhaps > they're not supposed to have any effect, perhaps it's a specific > combination of empty regions and something else that triggers some bug, > and perhaps that combination can no longer occur with your patch. The latter is my guess, but I haven't had time to investigate it. I *did* investigate whether the patch introduces other bugs, and haven't found any new ones. I successfully ran this large IFS and PPs test script from AT&T against dash with this patch: http://web.archive.org/web/20050414022354/http://www.research.att.com/~gsf/public/ifs.sh My own modernish regression test suite, which tests some pretty crazy things including lots of IFS and positional parameters stuff, also passes completely: git clone https://github.com/modernish/modernish cd modernish dash bin/modernish --test (still under development, may occasionally break) - M.
diff --git a/src/expand.c b/src/expand.c index 705fef7..c3d20a4 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;