summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2019-08-23 04:38:56 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2019-08-23 04:38:56 +0000
commit37544699556b1f45b227cc2ab5074f87130bfdb1 (patch)
tree5df7ce527bba73e378657da7c5170d2d57f567c6 /libexec
parent529a0027f707bd52837e9d9a507d00373c20cb78 (diff)
update tradcpp to 0.5.3
Diffstat (limited to 'libexec')
-rw-r--r--libexec/tradcpp/config.h16
-rw-r--r--libexec/tradcpp/directive.c27
-rw-r--r--libexec/tradcpp/eval.c10
-rw-r--r--libexec/tradcpp/files.c17
-rw-r--r--libexec/tradcpp/macro.c4
-rw-r--r--libexec/tradcpp/main.c2
-rw-r--r--libexec/tradcpp/place.c28
-rw-r--r--libexec/tradcpp/place.h3
-rw-r--r--libexec/tradcpp/version.h4
9 files changed, 85 insertions, 26 deletions
diff --git a/libexec/tradcpp/config.h b/libexec/tradcpp/config.h
index c8ad5f1fa80..c42dcc5ac5d 100644
--- a/libexec/tradcpp/config.h
+++ b/libexec/tradcpp/config.h
@@ -124,6 +124,22 @@
#define CONFIG_CPU "__ppc64__"
#elif defined(__ARM__)
#define CONFIG_CPU "__ARM__"
+#elif defined(__AARCH64__)
+#define CONFIG_CPU "__AARCH64__"
+#elif defined(__aarch64__)
+#define CONFIG_CPU "__aarch64__"
+#elif defined(__RISCV__)
+#define CONFIG_CPU "__RISCV__"
+#elif defined(__riscv__)
+#define CONFIG_CPU "__riscv__"
+#elif defined(__RISCV64__)
+#define CONFIG_CPU "__RISCV64__"
+#elif defined(__riscv64__)
+#define CONFIG_CPU "__riscv64__"
+#elif defined(__riscv64)
+#define CONFIG_CPU "__riscv64"
+#elif defined(__ia64__)
+#define CONFIG_CPU "__ia64__"
#else
/* let it go */
#endif
diff --git a/libexec/tradcpp/directive.c b/libexec/tradcpp/directive.c
index 0d5c98916b5..308b5ace6e8 100644
--- a/libexec/tradcpp/directive.c
+++ b/libexec/tradcpp/directive.c
@@ -114,7 +114,7 @@ oneword(const char *what, struct place *p2, char *line)
pos = strcspn(line, ws);
if (line[pos] != '\0') {
- p2->column += pos;
+ place_addcolumns(p2, pos);
complain(p2, "Garbage after %s argument", what);
complain_fail();
line[pos] = '\0';
@@ -348,13 +348,13 @@ d_define(struct lineplace *lp, struct place *p2, char *line)
argpos = pos;
pos = pos + strcspn(line+pos, "()");
if (line[pos] == '(') {
- p2->column += pos;
+ place_addcolumns(p2, pos);
complain(p2, "Left parenthesis in macro parameters");
complain_fail();
return;
}
if (line[pos] != ')') {
- p2->column += pos;
+ place_addcolumns(p2, pos);
complain(p2, "Unclosed macro parameter list");
complain_fail();
return;
@@ -378,10 +378,10 @@ d_define(struct lineplace *lp, struct place *p2, char *line)
pos += strspn(line+pos, ws);
p3 = *p2;
- p3.column += argpos;
+ place_addcolumns(&p3, argpos);
p4 = *p2;
- p4.column += pos;
+ place_addcolumns(&p4, pos);
if (argpos) {
debuglog(&lp->current, "Defining %s()", line);
@@ -490,7 +490,8 @@ d_line(struct lineplace *lp, struct place *p2, char *line)
errno = 0;
val = strtoul(text, &moretext, 10);
if (errno) {
- complain(&lp->current, "No line number in #line directive");
+ complain(&lp->current,
+ "Invalid line number in #line directive");
goto fail;
}
#if UINT_MAX < ULONG_MAX
@@ -502,7 +503,7 @@ d_line(struct lineplace *lp, struct place *p2, char *line)
#endif
moretext += strspn(moretext, ws);
moretextlen = strlen(moretext);
- lp->current.column += (moretext - text);
+ place_addcolumns(&lp->current, moretext - text);
if (moretextlen > 2 &&
moretext[0] == '"' && moretext[moretextlen-1] == '"') {
@@ -610,7 +611,7 @@ directive_gotdirective(struct lineplace *lp, char *line)
return;
}
skip = len + strspn(line+len, ws);
- p2.column += skip;
+ place_addcolumns(&p2, skip);
line += skip;
len = strlen(line);
@@ -667,10 +668,10 @@ directive_scancomments(const struct lineplace *lp, char *line, size_t len)
pos++;
}
if (line[pos] == '\n') {
- p2.line++;
+ place_addlines(&p2, 1);
p2.column = 0;
} else {
- p2.column++;
+ place_addcolumns(&p2, 1);
}
}
@@ -692,13 +693,13 @@ directive_gotline(struct lineplace *lp, char *line, size_t len)
if (len > 0 && line[0] == '#') {
skip = 1 + strspn(line + 1, ws);
assert(skip <= len);
- lp->current.column += skip;
+ place_addcolumns(&lp->current, skip);
assert(line[len] == '\0');
directive_gotdirective(lp, line+skip /*, length = len-skip */);
- lp->current.column += len-skip;
+ place_addcolumns(&lp->current, len-skip);
} else if (ifstate->curtrue) {
macro_sendline(&lp->current, line, len);
- lp->current.column += len;
+ place_addcolumns(&lp->current, len);
}
}
diff --git a/libexec/tradcpp/eval.c b/libexec/tradcpp/eval.c
index 870ac6cf14d..6a6bcad8193 100644
--- a/libexec/tradcpp/eval.c
+++ b/libexec/tradcpp/eval.c
@@ -708,29 +708,29 @@ tokenize(struct place *p, char *expr)
while (expr[pos] != '\0') {
len = strspn(expr+pos, ws);
pos += len;
- p->column += len;
+ place_addcolumns(p, len);
/* trailing whitespace is supposed to have been pruned */
assert(expr[pos] != '\0');
if (check_word(p, expr, pos, &len)) {
pos += len;
- p->column += len;
+ place_addcolumns(p, len);
continue;
}
if (check_tokens_2(p, expr, pos)) {
pos += 2;
- p->column += 2;
+ place_addcolumns(p, 2);
continue;
}
if (check_tokens_1(p, expr, pos)) {
pos++;
- p->column++;
+ place_addcolumns(p, 1);
continue;
}
complain(p, "Invalid character %u in #if-expression",
(unsigned char)expr[pos]);
complain_fail();
pos++;
- p->column++;
+ place_addcolumns(p, 1);
}
token(p, T_EOF, 0);
}
diff --git a/libexec/tradcpp/files.c b/libexec/tradcpp/files.c
index d49f56640a0..dae8ee76b40 100644
--- a/libexec/tradcpp/files.c
+++ b/libexec/tradcpp/files.c
@@ -163,6 +163,10 @@ countnls(const char *buf, size_t start, size_t limit)
for (i=start; i<limit; i++) {
if (buf[i] == '\n') {
count++;
+ if (count == 0) {
+ /* just return the max and error downstream */
+ return count - 1;
+ }
}
}
return count;
@@ -209,6 +213,12 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel)
/* need bigger buffer */
buf = dorealloc(buf, bufmax, bufmax*2);
bufmax = bufmax*2;
+ /* just in case someone's screwing around */
+ if (bufmax > 0xffffffff) {
+ complain(&places.current,
+ "Input line too long");
+ die();
+ }
}
if (ateof) {
@@ -231,7 +241,7 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel)
/* eof in middle of line */
ateof = true;
ptmp = places.current;
- ptmp.column += bufend - linestart;
+ place_addcolumns(&ptmp, bufend - linestart);
if (buf[bufend - 1] == '\n') {
complain(&ptmp, "Unclosed comment");
complain_fail();
@@ -257,7 +267,7 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel)
assert(buf[lineend] == '\n');
buf[lineend] = '\0';
nextlinestart = lineend+1;
- places.nextline.line++;
+ place_addlines(&places.nextline, 1);
/* check for CR/NL */
if (lineend > 0 && buf[lineend-1] == '\r') {
@@ -284,7 +294,8 @@ file_read(const struct placefile *pf, int fd, const char *name, bool toplevel)
assert(buf[lineend] == '\0');
/* count how many commented-out newlines we swallowed */
- places.nextline.line += countnls(buf, linestart, lineend);
+ place_addlines(&places.nextline,
+ countnls(buf, linestart, lineend));
/* process the line (even if it's empty) */
directive_gotline(&places, buf+linestart, lineend-linestart);
diff --git a/libexec/tradcpp/macro.c b/libexec/tradcpp/macro.c
index 147dfebb377..3ad0f6cf4c0 100644
--- a/libexec/tradcpp/macro.c
+++ b/libexec/tradcpp/macro.c
@@ -523,7 +523,7 @@ macro_parse_parameters(struct macro *m, struct place *p, const char *params)
while (params != NULL) {
len = strspn(params, ws);
params += len;
- p->column += len;
+ place_addcolumns(p, len);
s = strchr(params, ',');
if (s) {
len = s-params;
@@ -541,7 +541,7 @@ macro_parse_parameters(struct macro *m, struct place *p, const char *params)
stringarray_add(&m->params, param, NULL);
}
params = s;
- p->column += len;
+ place_addcolumns(p, len);
}
}
diff --git a/libexec/tradcpp/main.c b/libexec/tradcpp/main.c
index 9ce2ba1c76c..318c456f7cd 100644
--- a/libexec/tradcpp/main.c
+++ b/libexec/tradcpp/main.c
@@ -156,7 +156,7 @@ commandline_def(const struct place *p, char *str)
if (val) {
p2 = *p;
- p2.column += strlen(str);
+ place_addcolumns(&p2, strlen(str));
} else {
place_setbuiltin(&p2, 1);
}
diff --git a/libexec/tradcpp/place.c b/libexec/tradcpp/place.c
index 72ab47ccb04..a2e1e02637b 100644
--- a/libexec/tradcpp/place.c
+++ b/libexec/tradcpp/place.c
@@ -193,6 +193,34 @@ place_setfilestart(struct place *p, const struct placefile *pf)
p->column = 1;
}
+void
+place_addcolumns(struct place *p, unsigned cols)
+{
+ unsigned newcol;
+
+ newcol = p->column + cols;
+ if (newcol < p->column) {
+ /* overflow (use the old place to complain) */
+ complain(p, "Column numbering overflow");
+ die();
+ }
+ p->column = newcol;
+}
+
+void
+place_addlines(struct place *p, unsigned lines)
+{
+ unsigned nextline;
+
+ nextline = p->line + lines;
+ if (nextline < p->line) {
+ /* overflow (use the old place to complain) */
+ complain(p, "Line numbering overflow");
+ die();
+ }
+ p->line = nextline;
+}
+
const char *
place_getname(const struct place *p)
{
diff --git a/libexec/tradcpp/place.h b/libexec/tradcpp/place.h
index d18dd82cbf2..7dab0375583 100644
--- a/libexec/tradcpp/place.h
+++ b/libexec/tradcpp/place.h
@@ -53,6 +53,9 @@ void place_setbuiltin(struct place *p, unsigned num);
void place_setcommandline(struct place *p, unsigned word, unsigned column);
void place_setfilestart(struct place *p, const struct placefile *pf);
+void place_addcolumns(struct place *, unsigned cols);
+void place_addlines(struct place *, unsigned lines);
+
const char *place_getname(const struct place *);
const char *place_getparsedir(const struct place *incplace);
bool place_eq(const struct place *, const struct place *);
diff --git a/libexec/tradcpp/version.h b/libexec/tradcpp/version.h
index 3e0c5ca8531..bb77fd56eb6 100644
--- a/libexec/tradcpp/version.h
+++ b/libexec/tradcpp/version.h
@@ -29,5 +29,5 @@
#define VERSION_MAJOR "0"
#define VERSION_MINOR "5"
-#define VERSION_STRING "0.5.2"
-#define VERSION_LONG "NetBSD tradcpp 0.5.2"
+#define VERSION_STRING "0.5.3"
+#define VERSION_LONG "NetBSD tradcpp 0.5.3"