diff --git a/Makefile.in b/Makefile.in index 6362866..ee4fbc9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -34,7 +34,7 @@ bindir = @bindir@ srcdir = @srcdir@ -CC = @CC@ $(CPPFLAGS) +CC = @CC@ INSTALL = @INSTALL@ MKDIR_P = @MKDIR_P@ SHELL = /bin/sh @@ -43,8 +43,8 @@ SHELL = /bin/sh ## Bison is generating incorrect parsers. So do not use, for now # YACC = @YACC@ -CFLAGS = $(ADDCFLAGS) -I. -I$(srcdir) -W -Wall -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered @CFLAGS@ -CPPFLAGS = $(ADDCPPFLAGS) @CPPFLAGS@ +CPPFLAGS = $(ADDCPPFLAGS) -I. -I$(srcdir) @CPPFLAGS@ +CFLAGS = $(ADDCFLAGS) -W -Wall -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered @CFLAGS@ LDFLAGS = $(ADDLDFLAGS) @LDFLAGS@ LIBS = $(ADDLIBS) @LIBS@ @@ -68,10 +68,13 @@ GEN = esdump y.tab.c y.tab.h y.output token.h sigmsgs.c initial.c SIGFILES = @SIGFILES@ es : ${OFILES} initial.o - ${CC} -o es ${LDFLAGS} ${OFILES} initial.o ${LIBS} + ${CC} -o es ${CFLAGS} ${LDFLAGS} ${OFILES} initial.o ${LIBS} esdump : ${OFILES} dump.o - ${CC} -o esdump ${LDFLAGS} ${OFILES} dump.o ${LIBS} + ${CC} -o esdump ${CFLAGS} ${LDFLAGS} ${OFILES} dump.o ${LIBS} + +.c.o: + ${CC} -c -o $@ ${CFLAGS} ${CPPFLAGS} $< clean : rm -f es ${OFILES} ${GEN} dump.o initial.o diff --git a/es.h b/es.h index 24ff27b..0b9a53a 100644 --- a/es.h +++ b/es.h @@ -113,8 +113,8 @@ extern void undefer(int ticket); /* term.c */ +#define mkstr(str) (mkterm((str), NULL)) extern Term *mkterm(char *str, Closure *closure); -extern Term *mkstr(char *str); extern char *getstr(Term *term); extern Closure *getclosure(Term *term); extern Term *termcat(Term *t1, Term *t2); @@ -173,7 +173,7 @@ extern List *glom2(Tree *tree, Binding *binding, StrList **quotep); /* glob.c */ -extern char QUOTED[], UNQUOTED[]; +extern const char *QUOTED, *UNQUOTED; extern List *glob(List *list, StrList *quote); extern Boolean haswild(const char *pattern, const char *quoting); diff --git a/glob.c b/glob.c index c319870..dbf4cf1 100644 --- a/glob.c +++ b/glob.c @@ -6,7 +6,7 @@ #include "es.h" #include "gc.h" -char QUOTED[] = "QUOTED", UNQUOTED[] = "RAW"; +const char *QUOTED = "QUOTED", *UNQUOTED = "RAW"; /* hastilde -- true iff the first character is a ~ and it is not quoted */ static Boolean hastilde(const char *s, const char *q) { @@ -56,7 +56,7 @@ static List *dirmatch(const char *prefix, const char *dirname, const char *patte * opendir to handle a trailing slash. */ if (stat(dirname, &s) == -1 || (s.st_mode & S_IFMT) != S_IFDIR) - return NULL; + return NULL; if (!haswild(pattern, quote)) { char *name = str("%s%s", prefix, pattern); @@ -69,7 +69,7 @@ static List *dirmatch(const char *prefix, const char *dirname, const char *patte dirp = opendir(dirname); if (dirp == NULL) - return NULL; + return NULL; for (list = NULL, prevp = &list; (dp = readdir(dirp)) != NULL;) if (match(dp->d_name, pattern, quote) && (!ishiddenfile(dp->d_name) || *pattern == '.')) { @@ -95,7 +95,7 @@ static List *listglob(List *list, char *pattern, char *quote, size_t slashcount) assert(list->term != NULL); assert(!isclosure(list->term)); - + dir = getstr(list->term); dirlen = strlen(dir); if (dirlen + slashcount + 1 >= prefixlen) { @@ -175,7 +175,7 @@ static List *glob1(const char *pattern, const char *quote) { /* glob0 -- glob a list, (destructively) passing through entries we don't care about */ static List *glob0(List *list, StrList *quote) { List *result, **prevp, *expand1; - + for (result = NULL, prevp = &result; list != NULL; list = list->next, quote = quote->next) { char *str; if ( @@ -225,7 +225,7 @@ static char *expandhome(char *s, StrList *qp) { Ref(char *, home, getstr(list->term)); if (c == '\0') { string = home; - quote->str = QUOTED; + quote->str = (char *)QUOTED; } else { char *q; size_t pathlen = strlen(string); @@ -243,7 +243,7 @@ static char *expandhome(char *s, StrList *qp) { memset(&q[homelen], 'r', pathlen - slash); q[len] = '\0'; } else if (strchr(q, 'r') == NULL) - q = QUOTED; + q = (char *)QUOTED; else { q = gcalloc(len + 1, &StringTag); memset(q, 'q', homelen); diff --git a/glom.c b/glom.c index 28bfb48..5bd4a8f 100644 --- a/glom.c +++ b/glom.c @@ -30,9 +30,9 @@ static char *qcat(const char *q1, const char *q2, Term *t1, Term *t2) { assert(gcisblocked()); if (q1 == QUOTED && q2 == QUOTED) - return QUOTED; + return (char *)QUOTED; if (q1 == UNQUOTED && q2 == UNQUOTED) - return UNQUOTED; + return (char *)UNQUOTED; len1 = (q1 == QUOTED || q1 == UNQUOTED) ? strlen(getstr(t1)) : strlen(q1); len2 = (q2 == QUOTED || q2 == UNQUOTED) ? strlen(getstr(t2)) : strlen(q2); @@ -266,7 +266,7 @@ extern List *glom2(Tree *tree, Binding *binding, StrList **quotep) { switch (tp->kind) { case nWord: list = mklist(mkterm(tp->u[0].s, NULL), NULL); - qlist = mkstrlist(UNQUOTED, NULL); + qlist = mkstrlist((char *)UNQUOTED, NULL); tp = NULL; break; case nList: @@ -288,7 +288,7 @@ extern List *glom2(Tree *tree, Binding *binding, StrList **quotep) { list = glom1(tp, bp); Ref(List *, lp, list); for (; lp != NULL; lp = lp->next) - qlist = mkstrlist(QUOTED, qlist); + qlist = mkstrlist((char *)QUOTED, qlist); RefEnd(lp); tp = NULL; break; diff --git a/match.c b/match.c index 6b22e6f..c6c4d1b 100644 --- a/match.c +++ b/match.c @@ -21,6 +21,7 @@ enum { RANGE_FAIL = -1, RANGE_ERROR = -2 }; #define ISQUOTED(q, n) ((q) == QUOTED || ((q) != UNQUOTED && (q)[n] == 'q')) #define TAILQUOTE(q, n) ((q) == UNQUOTED ? UNQUOTED : ((q) + (n))) +#define QADVANCE(q, n) ((q) += (((q) == QUOTED || (q) == UNQUOTED) ? 0 : (n))) /* rangematch -- match a character against a character class */ static int rangematch(const char *p, const char *q, char c) { @@ -28,15 +29,15 @@ static int rangematch(const char *p, const char *q, char c) { Boolean neg; Boolean matched = FALSE; if (*p == '~' && !ISQUOTED(q, 0)) { - p++, q++; + p++, QADVANCE(q, 1); neg = TRUE; } else neg = FALSE; if (*p == ']' && !ISQUOTED(q, 0)) { - p++, q++; + p++, QADVANCE(q, 1); matched = (c == ']'); } - for (; *p != ']' || ISQUOTED(q, 0); p++, q++) { + for (; *p != ']' || ISQUOTED(q, 0); p++, QADVANCE(q, 1)) { if (*p == '\0') return RANGE_ERROR; /* bad syntax */ if (p[1] == '-' && !ISQUOTED(q, 1) && ((p[2] != ']' && p[2] != '\0') || ISQUOTED(q, 2))) { @@ -44,7 +45,7 @@ static int rangematch(const char *p, const char *q, char c) { if (c >= *p && c <= p[2]) matched = TRUE; p += 2; - q += 2; + QADVANCE(q, 2); } else if (*p == c) matched = TRUE; } diff --git a/signal.c b/signal.c index 527dd93..c3cc30c 100644 --- a/signal.c +++ b/signal.c @@ -185,6 +185,13 @@ extern void initsignals(Boolean interactive, Boolean allowdumps) { else if (h == SIG_DFL || h == SIG_ERR) sigeffect[sig] = sig_default; else +#ifdef __has_feature +# if __has_feature(address_sanitizer) || __has_feature(undefined_behavior_sanitizer) + if (sig == SIGKILL || sig == SIGFPE + || sig == SIGBUS || sig == SIGSEGV) + sigeffect[sig] = sig_default; else +# endif +#endif panic( "initsignals: bad incoming signal value for %s: %x", signame(sig), h diff --git a/term.c b/term.c index 4ca99ec..9897fc3 100644 --- a/term.c +++ b/term.c @@ -15,16 +15,6 @@ extern Term *mkterm(char *str, Closure *closure) { RefReturn(term); } -extern Term *mkstr(char *str) { - Term *term; - Ref(char *, string, str); - term = gcnew(Term); - term->str = string; - term->closure = NULL; - RefEnd(string); - return term; -} - extern Closure *getclosure(Term *term) { if (term->closure == NULL) { char *s = term->str;