klibc-bot for Herbert Xu
2020-Mar-28 21:49 UTC
[klibc] [klibc:update-dash] dash: eval: Always set localvar_stop
Commit-ID: a4d612ae4f36810afb28b497e867714a01cbec82 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=a4d612ae4f36810afb28b497e867714a01cbec82 Author: Herbert Xu <herbert at gondor.apana.org.au> AuthorDate: Thu, 31 May 2018 01:15:34 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sat, 28 Mar 2020 21:42:55 +0000 [klibc] dash: eval: Always set localvar_stop [ dash commit 42298df5898a62f0df893be3af029d7e981623bd ] The variable localvar_stop is set iff vlocal is true. gcc doesn't get this so we get a spurious warning. This patch fixes this by always calling pushlocalvars with vlocal and making it only actually do the push if vlocal is non-zero. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/eval.c | 9 +++------ usr/dash/var.c | 12 +++++++++--- usr/dash/var.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/usr/dash/eval.c b/usr/dash/eval.c index 7bb636e1..6652ccc0 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -809,6 +809,8 @@ evalcommand(union node *cmd, int flags) vflags = VEXPORT; } + localvar_stop = pushlocalvars(vlocal); + /* Reserve one extra spot at the front for shellexec. */ nargv = stalloc(sizeof (char *) * (argc + 2)); argv = ++nargv; @@ -828,7 +830,6 @@ evalcommand(union node *cmd, int flags) status = redirectsafe(cmd->ncmd.redirect, REDIR_PUSH|REDIR_SAVEFD2); if (unlikely(status)) { - vlocal = 0; bail: exitstatus = status; @@ -839,9 +840,6 @@ bail: goto out; } - if (likely(vlocal)) - localvar_stop = pushlocalvars(); - for (argp = cmd->ncmd.assign; argp; argp = argp->narg.next) { struct strlist **spp; @@ -920,8 +918,7 @@ out: popredir(execcmd); unwindredir(redir_stop); unwindfiles(file_stop); - if (likely(vlocal)) - unwindlocalvars(localvar_stop); + unwindlocalvars(localvar_stop); if (lastarg) /* dsl: I think this is intended to be used to support * '_' in 'vi' command mode during line editing... diff --git a/usr/dash/var.c b/usr/dash/var.c index 40743e5d..0d7e1db0 100644 --- a/usr/dash/var.c +++ b/usr/dash/var.c @@ -562,18 +562,24 @@ poplocalvars(int keep) /* * Create a new localvar environment. */ -struct localvar_list *pushlocalvars(void) +struct localvar_list *pushlocalvars(int push) { struct localvar_list *ll; + struct localvar_list *top; + + top = localvar_stack; + if (!push) + goto out; INTOFF; ll = ckmalloc(sizeof(*ll)); ll->lv = NULL; - ll->next = localvar_stack; + ll->next = top; localvar_stack = ll; INTON; - return ll->next; +out: + return top; } diff --git a/usr/dash/var.h b/usr/dash/var.h index 8759be46..e545e02c 100644 --- a/usr/dash/var.h +++ b/usr/dash/var.h @@ -147,7 +147,7 @@ int showvars(const char *, int, int); int exportcmd(int, char **); int localcmd(int, char **); void mklocal(char *name, int flags); -struct localvar_list *pushlocalvars(void); +struct localvar_list *pushlocalvars(int push); void poplocalvars(int); void unwindlocalvars(struct localvar_list *stop); int unsetcmd(int, char **);
Seemingly Similar Threads
- [klibc:update-dash] dash: eval: Replace with listsetvar with mklocal/setvareq
- [klibc:update-dash] eval: Restore input files in evalcommand
- [klibc:update-dash] dash: eval: Restore input files in evalcommand
- [klibc:update-dash] dash: var: Set IFS to fixed value at start time
- [klibc:update-dash] dash: eval: avoid leaking memory associated with redirections