summaryrefslogtreecommitdiffstats
path: root/bin/sh/histedit.c
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/sh/histedit.c
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/sh/histedit.c')
-rw-r--r--bin/sh/histedit.c31
1 files changed, 9 insertions, 22 deletions
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");
OpenPOWER on IntegriCloud