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)
This commit is contained in:
parent
ecb123b942
commit
39fa9f1c99
@ -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)
|
||||
|
@ -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");
|
||||
|
@ -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) "ef;
|
||||
(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) {
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user