Skip to content

Commit

Permalink
Import changes from mem-fixes branch
Browse files Browse the repository at this point in the history
commit b419df8
Also allow UndefinedBehaviorSanitizer signals

commit 1eb9c07
Fix invalid read operation in range_match

commit 6c29cfb
mkstr is now a macro wrapping mkterm

commit 0f13006
Allow AddressSanitizer signals

commit 61a292d
Include CPPFLAGS/CFLAGS where relevant
  • Loading branch information
memreflect committed Apr 6, 2022
1 parent b46361a commit 16c7f9e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
13 changes: 8 additions & 5 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bindir = @bindir@
srcdir = @srcdir@


CC = @CC@ $(CPPFLAGS)
CC = @CC@
INSTALL = @INSTALL@
MKDIR_P = @MKDIR_P@
SHELL = /bin/sh
Expand All @@ -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@

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions es.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 == '.')) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions glom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions match.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,31 @@ 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) {
const char *orig = p;
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))) {
/* check for [..-..] but ignore [..-] */
if (c >= *p && c <= p[2])
matched = TRUE;
p += 2;
q += 2;
QADVANCE(q, 2);
} else if (*p == c)
matched = TRUE;
}
Expand Down
7 changes: 7 additions & 0 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions term.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 16c7f9e

Please sign in to comment.