[v2 PATCH] eval: Always set localvar_stop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 30, 2018 at 04:59:47PM +0800, Herbert Xu wrote:
> The variable localvar_stop is set iff vlocal is true.  gcc doesn't
> get this so we need to silence the warning with uninitialized_var.
> 
> Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>

Here is a better patch:

---8<---
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@xxxxxxxxxxxxxxxxxxx>

diff --git a/src/eval.c b/src/eval.c
index c300d0c..6185db4 100644
--- a/src/eval.c
+++ b/src/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/src/var.c b/src/var.c
index 40743e5..0d7e1db 100644
--- a/src/var.c
+++ b/src/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/src/var.h b/src/var.h
index b2054f7..cd0477f 100644
--- a/src/var.h
+++ b/src/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 **);
-- 
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux