From b3fa5c528c79b27986a77c92a48b7f70e7f9e7d3 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 13 Oct 2017 18:17:09 +0100 Subject: 41877: Separate out SH_FILE_EXPANSION loop from parameter substitution. Parameter substitution can add nodes that need to be rescanned by it, but not by file expansion, so the two don't play well together. --- Src/subst.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'Src') diff --git a/Src/subst.c b/Src/subst.c index 8c290cccf..d027e3d83 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -108,7 +108,6 @@ prefork(LinkList list, int flags, int *ret_flags) queue_signals(); node = firstnode(list); while (node) { - LinkNode nextnode = 0; if ((flags & (PREFORK_SINGLE|PREFORK_ASSIGN)) == PREFORK_ASSIGN && (insnode = keyvalpairelement(list, node))) { node = insnode; @@ -137,23 +136,31 @@ prefork(LinkList list, int flags, int *ret_flags) * testing if cptr changed... */ setdata(node, cptr); - /* - * Advance now because we must not expand filenames again - * after string substitution (which may insert new nodes). - */ - nextnode = node; - incnode(nextnode); - } - if (!(node = stringsubst(list, node, - flags & ~(PREFORK_TYPESET|PREFORK_ASSIGN), - ret_flags, asssub))) { - unqueue_signals(); - return; } - if (isset(SHFILEEXPANSION)) - node = nextnode; else - incnode(node); + { + if (!(node = stringsubst(list, node, + flags & ~(PREFORK_TYPESET|PREFORK_ASSIGN), + ret_flags, asssub))) { + unqueue_signals(); + return; + } + } + incnode(node); + } + if (isset(SHFILEEXPANSION)) { + /* + * stringsubst() may insert new nodes, so doesn't work + * well in the same loop as file expansion. + */ + for (node = firstnode(list); node; incnode(node)) { + if (!(node = stringsubst(list, node, + flags & ~(PREFORK_TYPESET|PREFORK_ASSIGN), + ret_flags, asssub))) { + unqueue_signals(); + return; + } + } } for (node = firstnode(list); node; incnode(node)) { if (node == stop) -- cgit 1.4.1