summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2009-06-23 20:45:12 +0000
committerjilles <jilles@FreeBSD.org>2009-06-23 20:45:12 +0000
commit39fa9f1c9918ad9bb25af4f1bbce28c34cb2cd65 (patch)
treed592f11be2381156c3c2f8e6dd6f4bcfb70c2c6c /bin
parentecb123b94294aeb93d0b2ae271c070be043d1ba4 (diff)
downloadFreeBSD-src-39fa9f1c9918ad9bb25af4f1bbce28c34cb2cd65.zip
FreeBSD-src-39fa9f1c9918ad9bb25af4f1bbce28c34cb2cd65.tar.gz
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)
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/eval.c22
-rw-r--r--bin/sh/histedit.c31
-rw-r--r--bin/sh/parser.c20
-rw-r--r--bin/sh/var.c6
4 files changed, 18 insertions, 61 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 5cee55e..eeea605 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -589,22 +589,14 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
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, struct backcmd *backcmd)
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, struct backcmd *backcmd)
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, struct backcmd *backcmd)
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)
diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c
index 5698a8f..32b0448 100644
--- a/bin/sh/histedit.c
+++ b/bin/sh/histedit.c
@@ -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");
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index d17dc1a..54a80a7 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -898,19 +898,6 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
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) {
diff --git a/bin/sh/var.c b/bin/sh/var.c
index a12a568..2c1caf1 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -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;
OpenPOWER on IntegriCloud