From ce6cba49be9c5d381a41f1baac81af3e999e298f Mon Sep 17 00:00:00 2001 From: millert Date: Thu, 25 Jan 2024 16:40:51 +0000 Subject: [PATCH] Update awk to the Jan 22, 2024 version. --- usr.bin/awk/FIXES | 13 ++++++++++++- usr.bin/awk/b.c | 30 ++++++++++++++---------------- usr.bin/awk/main.c | 11 +++++------ usr.bin/awk/run.c | 21 ++++++++++++--------- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES index d77bec29c62..3b059250d5c 100644 --- a/usr.bin/awk/FIXES +++ b/usr.bin/awk/FIXES @@ -25,11 +25,22 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the second edition of the AWK book was published in September 2023. +Jan 22, 2024: + Restore the ability to compile with g++. Thanks to + Arnold Robbins. + +Dec 24, 2023: + matchop dereference after free problem fix when the first + argument is a function call. thanks to Oguz Ismail Uysal. + Fix inconsistent handling of --csv and FS set in the + command line. Thanks to Wilbert van der Poel. + casting changes to int for is* functions. + Nov 27, 2023: Fix exit status of system on MacOS. update to REGRESS. Thanks to Arnold Robbins. Fix inconsistent handling of -F and --csv, and loss of csv - mode when FS is set. Thanks to Wilbert van der Poel. + mode when FS is set. Nov 24, 2023: Fix issue #199: gototab improvements to dynamically resize the diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 523e3ee195c..bc3f06fd320 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.49 2023/11/25 16:31:33 millert Exp $ */ +/* $OpenBSD: b.c,v 1.50 2024/01/25 16:40:51 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -117,7 +117,7 @@ static int entry_cmp(const void *l, const void *r); static int get_gototab(fa*, int, int); static int set_gototab(fa*, int, int, int); static void clear_gototab(fa*, int); -extern int u8_rune(int *, const uschar *); +extern int u8_rune(int *, const char *); static int * intalloc(size_t n, const char *f) @@ -422,7 +422,7 @@ int *cclenter(const char *argp) /* add a character class */ FATAL("out of space for character class [%.10s...] 1", p); bp = buf; for (i = 0; *p != 0; ) { - n = u8_rune(&c, p); + n = u8_rune(&c, (const char *) p); p += n; if (c == '\\') { c = quoted(&p); @@ -430,7 +430,7 @@ int *cclenter(const char *argp) /* add a character class */ if (*p != 0) { c = bp[-1]; /* c2 = *p++; */ - n = u8_rune(&c2, p); + n = u8_rune(&c2, (const char *) p); p += n; if (c2 == '\\') c2 = quoted(&p); /* BUG: sets p, has to be u8 size */ @@ -624,7 +624,7 @@ static int get_gototab(fa *f, int state, int ch) /* hide gototab inplementation key.ch = ch; key.state = 0; /* irrelevant */ - item = bsearch(& key, f->gototab[state].entries, + item = (gtte *) bsearch(& key, f->gototab[state].entries, f->gototab[state].inuse, sizeof(gtte), entry_cmp); @@ -668,7 +668,7 @@ static int set_gototab(fa *f, int state, int ch, int val) /* hide gototab inplem key.ch = ch; key.state = 0; /* irrelevant */ - item = bsearch(& key, f->gototab[state].entries, + item = (gtte *) bsearch(& key, f->gototab[state].entries, f->gototab[state].inuse, sizeof(gtte), entry_cmp); @@ -716,7 +716,7 @@ int match(fa *f, const char *p0) /* shortest match ? */ return(1); do { /* assert(*p < NCHARS); */ - n = u8_rune(&rune, p); + n = u8_rune(&rune, (const char *) p); if ((ns = get_gototab(f, s, rune)) != 0) s = ns; else @@ -749,7 +749,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */ if (f->out[s]) /* final state */ patlen = q-p; /* assert(*q < NCHARS); */ - n = u8_rune(&rune, q); + n = u8_rune(&rune, (const char *) q); if ((ns = get_gototab(f, s, rune)) != 0) s = ns; else @@ -780,7 +780,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */ s = 2; if (*p == 0) break; - n = u8_rune(&rune, p); + n = u8_rune(&rune, (const char *) p); p += n; } while (1); /* was *p++ */ return (0); @@ -805,7 +805,7 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */ if (f->out[s]) /* final state */ patlen = q-p; /* assert(*q < NCHARS); */ - n = u8_rune(&rune, q); + n = u8_rune(&rune, (const char *) q); if ((ns = get_gototab(f, s, rune)) != 0) s = ns; else @@ -893,7 +893,7 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum) } } - j += u8_rune(&c, (uschar *)j); + j += u8_rune(&c, j); if ((ns = get_gototab(pfa, s, c)) != 0) s = ns; @@ -913,7 +913,7 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum) break; /* best match found */ /* no match at origin i, next i and start over */ - i += u8_rune(&c, (uschar *)i); + i += u8_rune(&c, i); if (c == 0) break; /* no match */ j = i; @@ -1234,8 +1234,6 @@ static int repeat(const uschar *reptok, int reptoklen, const uschar *atom, return 0; } -extern int u8_rune(int *, const uschar *); /* run.c; should be in header file */ - int relex(void) /* lexical analyzer for reparse */ { int c, n; @@ -1253,7 +1251,7 @@ int relex(void) /* lexical analyzer for reparse */ rescan: starttok = prestr; - if ((n = u8_rune(&rlxval, prestr)) > 1) { + if ((n = u8_rune(&rlxval, (const char *) prestr)) > 1) { prestr += n; starttok = prestr; return CHAR; @@ -1300,7 +1298,7 @@ rescan: if (!adjbuf((char **) &buf, &bufsz, n, n, (char **) &bp, "relex1")) FATAL("out of space for reg expr %.10s...", lastre); for (; ; ) { - if ((n = u8_rune(&rlxval, prestr)) > 1) { + if ((n = u8_rune(&rlxval, (const char *) prestr)) > 1) { for (i = 0; i < n; i++) *bp++ = *prestr++; continue; diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c index 3ec64332ff5..481e98b078a 100644 --- a/usr.bin/awk/main.c +++ b/usr.bin/awk/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.67 2023/11/28 20:54:38 millert Exp $ */ +/* $OpenBSD: main.c,v 1.68 2024/01/25 16:40:51 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -23,7 +23,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -const char *version = "version 20231127"; +const char *version = "version 20240122"; #define DEBUG #include @@ -180,8 +180,6 @@ int main(int argc, char *argv[]) } if (strcmp(argv[1], "--csv") == 0) { /* turn on csv input processing */ CSV = true; - if (fs) - WARNING("danger: don't set FS when --csv is in effect"); argc--; argv++; continue; @@ -203,8 +201,6 @@ int main(int argc, char *argv[]) break; case 'F': /* set field separator */ fs = setfs(getarg(&argc, &argv, "no field separator")); - if (CSV) - WARNING("danger: don't set FS when --csv is in effect"); break; case 'v': /* -v a=1 to be done NOW. one -v for each */ vn = getarg(&argc, &argv, "no variable name"); @@ -238,6 +234,9 @@ int main(int argc, char *argv[]) } } + if (CSV && (fs != NULL || lookup("FS", symtab) != NULL)) + WARNING("danger: don't set FS when --csv is in effect"); + /* argv[1] is now the first argument */ if (npfile == 0) { /* no -f; first argument is program */ if (argc <= 1) { diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index af1153f6b7d..73ab148952b 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.83 2023/11/28 20:54:38 millert Exp $ */ +/* $OpenBSD: run.c,v 1.84 2024/01/25 16:40:51 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -796,7 +796,7 @@ int runetochar(char *str, int c) Cell *matchop(Node **a, int n) /* ~ and match() */ { - Cell *x, *y; + Cell *x, *y, *z; char *s, *t; int i; int cstart, cpatlen, len; @@ -818,7 +818,7 @@ Cell *matchop(Node **a, int n) /* ~ and match() */ i = (*mf)(pfa, s); tempfree(y); } - tempfree(x); + z = x; if (n == MATCHFCN) { int start = patbeg - s + 1; /* origin 1 */ if (patlen < 0) { @@ -840,11 +840,13 @@ Cell *matchop(Node **a, int n) /* ~ and match() */ x = gettemp(); x->tval = NUM; x->fval = start; - return x; } else if ((n == MATCH && i == 1) || (n == NOTMATCH && i == 0)) - return(True); + x = True; else - return(False); + x = False; + + tempfree(z); + return x; } @@ -1299,7 +1301,8 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co if (bs == NULL) { // invalid character // use unicode invalid character, 0xFFFD - bs = "\357\277\275"; + static char invalid_char[] = "\357\277\275"; + bs = invalid_char; count = 3; } t = bs; @@ -2567,7 +2570,7 @@ Cell *dosub(Node **a, int subop) /* sub and gsub */ start = getsval(x); while (pmatch(pfa, start)) { if (buf == NULL) { - if ((pb = buf = malloc(bufsz)) == NULL) + if ((pb = buf = (char *) malloc(bufsz)) == NULL) FATAL("out of memory in dosub"); tempstat = pfa->initstat; pfa->initstat = 2; @@ -2672,7 +2675,7 @@ Cell *gensub(Node **a, int nnn) /* global selective substitute */ int mflag, tempstat, num, whichm; int bufsz = recsize; - if ((buf = malloc(bufsz)) == NULL) + if ((buf = (char *) malloc(bufsz)) == NULL) FATAL("out of memory in gensub"); mflag = 0; /* if mflag == 0, can replace empty string */ num = 0; -- 2.20.1