svn commit: r194765 - head/bin/sh

Jilles Tjoelker jilles at FreeBSD.org
Tue Jun 23 20:45:13 UTC 2009


Author: jilles
Date: Tue Jun 23 20:45:12 2009
New Revision: 194765
URL: http://svn.freebsd.org/changeset/base/194765

Log:
  sh: Improve handling of setjmp/longjmp volatile:
  - remove ineffective and unnecessary (void) &var; [1]
  - remove some unnecessary volatile keywords
  - add a necessary volatile keyword
  - save the old handler before doing something that could use the saved
    value
  
  Submitted by:	Christoph Mallon [1]
  Approved by:	ed (mentor)

Modified:
  head/bin/sh/eval.c
  head/bin/sh/histedit.c
  head/bin/sh/parser.c
  head/bin/sh/var.c

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c	Tue Jun 23 20:38:35 2009	(r194764)
+++ head/bin/sh/eval.c	Tue Jun 23 20:45:12 2009	(r194765)
@@ -589,22 +589,14 @@ evalcommand(union node *cmd, int flags, 
 	struct cmdentry cmdentry;
 	struct job *jp;
 	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	char *volatile savecmdname;
-	volatile struct shparam saveparam;
-	struct localvar *volatile savelocalvars;
+	struct jmploc *savehandler;
+	char *savecmdname;
+	struct shparam saveparam;
+	struct localvar *savelocalvars;
 	volatile int e;
 	char *lastarg;
 	int realstatus;
 	int do_clearcmdentry;
-#ifdef __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &argv;
-	(void) &argc;
-	(void) &lastarg;
-	(void) &flags;
-	(void) &do_clearcmdentry;
-#endif
 
 	/* First expand the arguments. */
 	TRACE(("evalcommand(%p, %d) called\n", (void *)cmd, flags));
@@ -779,9 +771,10 @@ evalcommand(union node *cmd, int flags, 
 		savelocalvars = localvars;
 		localvars = NULL;
 		INTON;
+		savehandler = handler;
 		if (setjmp(jmploc.loc)) {
 			if (exception == EXSHELLPROC)
-				freeparam((struct shparam *)&saveparam);
+				freeparam(&saveparam);
 			else {
 				freeparam(&shellparam);
 				shellparam = saveparam;
@@ -791,7 +784,6 @@ evalcommand(union node *cmd, int flags, 
 			handler = savehandler;
 			longjmp(handler->loc, 1);
 		}
-		savehandler = handler;
 		handler = &jmploc;
 		for (sp = varlist.list ; sp ; sp = sp->next)
 			mklocal(sp->text);
@@ -830,12 +822,12 @@ evalcommand(union node *cmd, int flags, 
 		savecmdname = commandname;
 		cmdenviron = varlist.list;
 		e = -1;
+		savehandler = handler;
 		if (setjmp(jmploc.loc)) {
 			e = exception;
 			exitstatus = (e == EXINT)? SIGINT+128 : 2;
 			goto cmddone;
 		}
-		savehandler = handler;
 		handler = &jmploc;
 		redirect(cmd->ncmd.redirect, mode);
 		if (cmdentry.special)

Modified: head/bin/sh/histedit.c
==============================================================================
--- head/bin/sh/histedit.c	Tue Jun 23 20:38:35 2009	(r194764)
+++ head/bin/sh/histedit.c	Tue Jun 23 20:45:12 2009	(r194765)
@@ -173,25 +173,11 @@ histcmd(int argc, char **argv)
 	char *pat = NULL, *repl;
 	static int active = 0;
 	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
-	char editfile[PATH_MAX];
+	struct jmploc *savehandler;
+	char editfilestr[PATH_MAX];
+	char *volatile editfile;
 	FILE *efp;
 	int oldhistnum;
-#ifdef __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &editor;
-	(void) &lflg;
-	(void) &nflg;
-	(void) &rflg;
-	(void) &sflg;
-	(void) &firststr;
-	(void) &laststr;
-	(void) &pat;
-	(void) &repl;
-	(void) &efp;
-	(void) &argc;
-	(void) &argv;
-#endif
 
 	if (hist == NULL)
 		error("history not active");
@@ -232,19 +218,19 @@ histcmd(int argc, char **argv)
 	 */
 	if (lflg == 0 || editor || sflg) {
 		lflg = 0;	/* ignore */
-		editfile[0] = '\0';
+		editfile = NULL;
 		/*
 		 * Catch interrupts to reset active counter and
 		 * cleanup temp files.
 		 */
+		savehandler = handler;
 		if (setjmp(jmploc.loc)) {
 			active = 0;
-			if (*editfile)
+			if (editfile)
 				unlink(editfile);
 			handler = savehandler;
 			longjmp(handler->loc, 1);
 		}
-		savehandler = handler;
 		handler = &jmploc;
 		if (++active > MAXHISTLOOPS) {
 			active = 0;
@@ -318,9 +304,10 @@ histcmd(int argc, char **argv)
 	if (editor) {
 		int fd;
 		INTOFF;		/* easier */
-		sprintf(editfile, "%s/_shXXXXXX", _PATH_TMP);
-		if ((fd = mkstemp(editfile)) < 0)
+		sprintf(editfilestr, "%s/_shXXXXXX", _PATH_TMP);
+		if ((fd = mkstemp(editfilestr)) < 0)
 			error("can't create temporary file %s", editfile);
+		editfile = editfilestr;
 		if ((efp = fdopen(fd, "w")) == NULL) {
 			close(fd);
 			error("can't allocate stdio buffer for temp");

Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c	Tue Jun 23 20:38:35 2009	(r194764)
+++ head/bin/sh/parser.c	Tue Jun 23 20:45:12 2009	(r194765)
@@ -898,19 +898,6 @@ readtoken1(int firstc, char const *synta
 	int oldstyle;
 	char const *prevsyntax;	/* syntax before arithmetic */
 	int synentry;
-#ifdef __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &out;
-	(void) &quotef;
-	(void) &dblquote;
-	(void) &varnest;
-	(void) &arinest;
-	(void) &parenlevel;
-	(void) &oldstyle;
-	(void) &prevsyntax;
-	(void) &syntax;
-	(void) &synentry;
-#endif
 
 	startlinno = plinno;
 	dblquote = 0;
@@ -1320,13 +1307,9 @@ parsebackq: {
 	union node *n;
 	char *volatile str;
 	struct jmploc jmploc;
-	struct jmploc *volatile savehandler;
+	struct jmploc *const savehandler = handler;
 	int savelen;
 	int saveprompt;
-#ifdef __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &saveprompt;
-#endif
 
 	savepbq = parsebackquote;
 	if (setjmp(jmploc.loc)) {
@@ -1343,7 +1326,6 @@ parsebackq: {
 		str = ckmalloc(savelen);
 		memcpy(str, stackblock(), savelen);
 	}
-	savehandler = handler;
 	handler = &jmploc;
 	INTON;
         if (oldstyle) {

Modified: head/bin/sh/var.c
==============================================================================
--- head/bin/sh/var.c	Tue Jun 23 20:38:35 2009	(r194764)
+++ head/bin/sh/var.c	Tue Jun 23 20:45:12 2009	(r194765)
@@ -193,12 +193,8 @@ int
 setvarsafe(char *name, char *val, int flags)
 {
 	struct jmploc jmploc;
-	struct jmploc *volatile savehandler = handler;
+	struct jmploc *const savehandler = handler;
 	int err = 0;
-#ifdef __GNUC__
-	/* Avoid longjmp clobbering */
-	(void) &err;
-#endif
 
 	if (setjmp(jmploc.loc))
 		err = 1;


More information about the svn-src-all mailing list