diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2008-10-06 20:38:34 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2008-10-06 20:38:34 +0000 |
commit | 3b748a35eed231f2cc347c4fe4af63f6177df3b2 (patch) | |
tree | df44da82a40a031c5cca741883e0db58446bf25e /usr.bin/awk | |
parent | 3ac68e389539d6e81454f9bef2ae4364806ffb9c (diff) |
Update awk to version 20071023; OK deraadt@
Diffstat (limited to 'usr.bin/awk')
-rw-r--r-- | usr.bin/awk/FIXES | 69 | ||||
-rw-r--r-- | usr.bin/awk/awk.h | 4 | ||||
-rw-r--r-- | usr.bin/awk/awkgram.y | 4 | ||||
-rw-r--r-- | usr.bin/awk/b.c | 42 | ||||
-rw-r--r-- | usr.bin/awk/lex.c | 36 | ||||
-rw-r--r-- | usr.bin/awk/lib.c | 25 | ||||
-rw-r--r-- | usr.bin/awk/main.c | 14 | ||||
-rw-r--r-- | usr.bin/awk/maketab.c | 5 | ||||
-rw-r--r-- | usr.bin/awk/run.c | 50 |
9 files changed, 161 insertions, 88 deletions
diff --git a/usr.bin/awk/FIXES b/usr.bin/awk/FIXES index 48ad1a8f200..b318e2a1a72 100644 --- a/usr.bin/awk/FIXES +++ b/usr.bin/awk/FIXES @@ -1,4 +1,4 @@ -/* $OpenBSD: FIXES,v 1.13 2004/12/30 01:52:48 millert Exp $ */ +/* $OpenBSD: FIXES,v 1.14 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -26,6 +26,73 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. +Oct 23, 2007: + minor fix in lib.c: increase inputFS to 100, change malloc + for fields to n+1. + + fixed memory fault caused by out of order test in setsval. + + thanks to david o'brien, freebsd, for both fixes. + +May 1, 2007: + fiddle in makefile to fix for BSD make; thanks to igor sobrado. + +Mar 31, 2007: + fixed some null pointer refs calling adjbuf. + +Feb 21, 2007: + fixed a bug in matching the null RE in sub and gsub. thanks to al aho + who actually did the fix (in b.c), and to wolfgang seeberg for finding + it and providing a very compact test case. + + fixed quotation in b.c; thanks to Hal Pratt and the Princeton Dante + Project. + + removed some no-effect asserts in run.c. + + fiddled maketab.c to not complain about bison-generated values. + + removed the obsolete -V argument; fixed --version to print the + version and exit. + + fixed wording and an outright error in the usage message; thanks to igor + sobrado and jason mcintyre. + + fixed a bug in -d that caused core dump if no program followed. + +Jan 1, 2007: + dropped mac.code from makefile; there are few non-MacOSX + mac's these days. + +Jan 17, 2006: + system() not flagged as unsafe in the unadvertised -safe option. + found it while enhancing tests before shipping the ;login: article. + practice what you preach. + + removed the 9-years-obsolete -mr and -mf flags. + + added -version and --version options. + + core dump on linux with BEGIN {nextfile}, now fixed. + + removed some #ifdef's in run.c and lex.c that appear to no + longer be necessary. + +Apr 24, 2005: + modified lib.c so that values of $0 et al are preserved in the END + block, apparently as required by posix. thanks to havard eidnes + for the report and code. + +Jan 14, 2005: + fixed infinite loop in parsing, originally found by brian tsang. + thanks to arnold robbins for a suggestion that started me + rethinking it. + +Dec 31, 2004: + prevent overflow of -f array in main, head off potential error in + call of SYNTAX(), test malloc return in lib.c, all with thanks to + todd miller. + Dec 22, 2004: cranked up size of NCHARS; coverity thinks it can be overrun with smaller size, and i think that's right. added some assertions to b.c diff --git a/usr.bin/awk/awk.h b/usr.bin/awk/awk.h index 8cbfda041a8..49fbcbe8940 100644 --- a/usr.bin/awk/awk.h +++ b/usr.bin/awk/awk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: awk.h,v 1.12 2008/06/04 14:04:42 pyr Exp $ */ +/* $OpenBSD: awk.h,v 1.13 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -31,7 +31,7 @@ typedef double Awkfloat; typedef unsigned char uschar; -#define xfree(a) { if ((a) != NULL) { free((char *) a); a = NULL; } } +#define xfree(a) { if ((a) != NULL) { free((void *) (a)); (a) = NULL; } } #define NN(p) ((p) ? (p) : "(null)") /* guaranteed non-null for dprintf */ diff --git a/usr.bin/awk/awkgram.y b/usr.bin/awk/awkgram.y index 03a872fd045..d19ea86e5cd 100644 --- a/usr.bin/awk/awkgram.y +++ b/usr.bin/awk/awkgram.y @@ -1,4 +1,4 @@ -/* $OpenBSD: awkgram.y,v 1.7 2001/09/08 00:12:40 millert Exp $ */ +/* $OpenBSD: awkgram.y,v 1.8 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -51,7 +51,7 @@ Node *arglist = 0; /* list of args for current function */ %token <i> NL ',' '{' '(' '|' ';' '/' ')' '}' '[' ']' %token <i> ARRAY %token <i> MATCH NOTMATCH MATCHOP -%token <i> FINAL DOT ALL CCL NCCL CHAR OR STAR QUEST PLUS +%token <i> FINAL DOT ALL CCL NCCL CHAR OR STAR QUEST PLUS EMPTYRE %token <i> AND BOR APPEND EQ GE GT LE LT NE IN %token <i> ARG BLTIN BREAK CLOSE CONTINUE DELETE DO EXIT FOR FUNC %token <i> SUB GSUB IF INDEX LSUBSTR MATCHFCN NEXT NEXTFILE diff --git a/usr.bin/awk/b.c b/usr.bin/awk/b.c index 9c1e96f166b..03018c10012 100644 --- a/usr.bin/awk/b.c +++ b/usr.bin/awk/b.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b.c,v 1.14 2007/09/02 15:19:31 deraadt Exp $ */ +/* $OpenBSD: b.c,v 1.15 2008/10/06 20:38:33 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. ****************************************************************/ -/* lasciate ogne speranza, voi ch'entrate. */ +/* lasciate ogne speranza, voi ch'intrate. */ #define DEBUG @@ -45,10 +45,11 @@ THIS SOFTWARE. #define parent(v) (v)->nnext #define LEAF case CCL: case NCCL: case CHAR: case DOT: case FINAL: case ALL: +#define ELEAF case EMPTYRE: /* empty string in regexp */ #define UNARY case STAR: case PLUS: case QUEST: /* encoding in tree Nodes: - leaf (CCL, NCCL, CHAR, DOT, FINAL, ALL): + leaf (CCL, NCCL, CHAR, DOT, FINAL, ALL, EMPTYRE): left is index, right contains value or pointer to value unary (STAR, PLUS, QUEST): left is child, right is null binary (CAT, OR): left and right are children @@ -183,6 +184,7 @@ int makeinit(fa *f, int anchor) void penter(Node *p) /* set up parent pointers and leaf indices */ { switch (type(p)) { + ELEAF LEAF info(p) = poscnt; poscnt++; @@ -207,6 +209,7 @@ void penter(Node *p) /* set up parent pointers and leaf indices */ void freetr(Node *p) /* free parse tree */ { switch (type(p)) { + ELEAF LEAF xfree(p); break; @@ -310,7 +313,7 @@ char *cclenter(const char *argp) /* add a character class */ continue; } while (c < c2) { - if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, "cclenter1")) FATAL("out of space for character class [%.10s...] 2", p); *bp++ = ++c; i++; @@ -318,7 +321,7 @@ char *cclenter(const char *argp) /* add a character class */ continue; } } - if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, "cclenter2")) FATAL("out of space for character class [%.10s...] 3", p); *bp++ = c; i++; @@ -340,6 +343,7 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo int *p; switch (type(v)) { + ELEAF LEAF f->re[info(v)].ltype = type(v); f->re[info(v)].lval.np = right(v); @@ -376,11 +380,12 @@ void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfo } int first(Node *p) /* collects initially active leaves of p into setvec */ - /* returns 1 if p matches empty string */ + /* returns 0 if p matches empty string */ { int b, lp; switch (type(p)) { + ELEAF LEAF lp = info(p); /* look for high-water mark of subscripts */ while (setcnt >= maxsetvec || lp >= maxsetvec) { /* guessing here! */ @@ -390,6 +395,10 @@ int first(Node *p) /* collects initially active leaves of p into setvec */ if (setvec == 0 || tmpset == 0) overflo("out of space in first()"); } + if (type(p) == EMPTYRE) { + setvec[lp] = 0; + return(0); + } if (setvec[lp] != 1) { setvec[lp] = 1; setcnt++; @@ -466,7 +475,7 @@ int match(fa *f, const char *p0) /* shortest match ? */ if (f->out[s]) return(1); do { - assert(*p < NCHARS); + /* assert(*p < NCHARS); */ if ((ns = f->gototab[s][*p]) != 0) s = ns; else @@ -497,7 +506,7 @@ int pmatch(fa *f, const char *p0) /* longest match, for sub */ do { if (f->out[s]) /* final state */ patlen = q-p; - assert(*q < NCHARS); + /* assert(*q < NCHARS); */ if ((ns = f->gototab[s][*q]) != 0) s = ns; else @@ -555,7 +564,7 @@ int nematch(fa *f, const char *p0) /* non-empty match, for sub */ do { if (f->out[s]) /* final state */ patlen = q-p; - assert(*q < NCHARS); + /* assert(*q < NCHARS); */ if ((ns = f->gototab[s][*q]) != 0) s = ns; else @@ -602,9 +611,10 @@ Node *reparse(const char *p) /* parses regular expression pointed to by p */ lastre = prestr = (uschar *) p; /* prestr points to string to be parsed */ rtok = relex(); /* GNU compatibility: an empty regexp matches anything */ - if (rtok == '\0') + if (rtok == '\0') { /* FATAL("empty regular expression"); previous */ - return(op2(ALL, NIL, NIL)); + return(op2(EMPTYRE, NIL, NIL)); + } np = regexp(); if (rtok != '\0') FATAL("syntax error in regular expression %s at %s", lastre, prestr); @@ -628,6 +638,9 @@ Node *primary(void) case ALL: rtok = relex(); return (unary(op2(ALL, NIL, NIL))); + case EMPTYRE: + rtok = relex(); + return (unary(op2(ALL, NIL, NIL))); case DOT: rtok = relex(); return (unary(op2(DOT, NIL, NIL))); @@ -667,7 +680,7 @@ Node *primary(void) Node *concat(Node *np) { switch (rtok) { - case CHAR: case DOT: case ALL: case CCL: case NCCL: case '$': case '(': + case CHAR: case DOT: case ALL: case EMPTYRE: case CCL: case NCCL: case '$': case '(': return (concat(op2(CAT, np, primary()))); } return (np); @@ -788,7 +801,7 @@ int relex(void) /* lexical analyzer for reparse */ else cflag = 0; n = 2 * strlen((const char *) prestr)+1; - if (!adjbuf((char **) &buf, &bufsz, n, n, (char **) &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, n, n, (char **) &bp, "relex1")) FATAL("out of space for reg expr %.10s...", lastre); for (; ; ) { if ((c = *prestr++) == '\\') { @@ -807,7 +820,7 @@ int relex(void) /* lexical analyzer for reparse */ prestr[2 + cc->cc_namelen] == ']') { prestr += cc->cc_namelen + 3; for (i = 0; i < NCHARS; i++) { - if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, 0)) + if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, "relex2")) FATAL("out of space for reg expr %.10s...", lastre); if (cc->cc_func(i)) { *bp++ = i; @@ -856,6 +869,7 @@ int cgoto(fa *f, int s, int c) if ((k == CHAR && c == ptoi(f->re[p[i]].lval.np)) || (k == DOT && c != 0 && c != HAT) || (k == ALL && c != 0) + || (k == EMPTYRE && c != 0) || (k == CCL && member(c, (char *) f->re[p[i]].lval.up)) || (k == NCCL && !member(c, (char *) f->re[p[i]].lval.up) && c != 0 && c != HAT)) { q = f->re[p[i]].lfollow; diff --git a/usr.bin/awk/lex.c b/usr.bin/awk/lex.c index 46252f1f335..f355dd7fcd7 100644 --- a/usr.bin/awk/lex.c +++ b/usr.bin/awk/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.10 2008/06/04 14:04:42 pyr Exp $ */ +/* $OpenBSD: lex.c,v 1.11 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -96,12 +96,7 @@ Keyword keywords[] ={ /* keep sorted: binary searched */ { "xor", FXOR, BLTIN }, }; -#define DEBUG -#ifdef DEBUG #define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); } -#else -#define RET(x) return(x) -#endif int peek(void); int gettok(char **, int *); @@ -133,7 +128,7 @@ int gettok(char **pbuf, int *psz) /* get next input token */ if (isalpha(c) || c == '_') { /* it's a varname */ for ( ; (c = input()) != 0; ) { if (bp-buf >= sz) - if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0)) + if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok")) FATAL( "out of space for name %.10s...", buf ); if (isalnum(c) || c == '_') *bp++ = c; @@ -145,12 +140,12 @@ int gettok(char **pbuf, int *psz) /* get next input token */ } *bp = 0; retc = 'a'; /* alphanumeric */ - } else { /* it's a number */ + } else { /* maybe it's a number, but could be . */ char *rem; /* read input until can't be a number */ for ( ; (c = input()) != 0; ) { if (bp-buf >= sz) - if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0)) + if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok")) FATAL( "out of space for number %.10s...", buf ); if (isdigit(c) || c == 'e' || c == 'E' || c == '.' || c == '+' || c == '-') @@ -162,14 +157,14 @@ int gettok(char **pbuf, int *psz) /* get next input token */ } *bp = 0; strtod(buf, &rem); /* parse the number */ - unputstr(rem); /* put rest back for later */ -/* printf("unputstr [%s], buf [%s]\n", rem, buf); */ if (rem == buf) { /* it wasn't a valid number at all */ - buf[1] = 0; /* so return one character as token */ + buf[1] = 0; /* return one character as token */ retc = buf[0]; /* character is its own type */ + unputstr(rem+1); /* put rest back for later */ } else { /* some prefix was a number */ - rem[0] = 0; /* so truncate where failure started */ - retc = '0'; /* number */ + unputstr(rem); /* put rest back for later */ + rem[0] = 0; /* truncate buf after number part */ + retc = '0'; /* type is number */ } } *pbuf = buf; @@ -187,7 +182,7 @@ int yylex(void) { int c; static char *buf = 0; - static int bufsize = 500; + static int bufsize = 5; /* BUG: setting this small causes core dump! */ if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL) FATAL( "out of space in yylex" ); @@ -199,10 +194,8 @@ int yylex(void) reg = 0; return regexpr(); } -/* printf("top\n"); */ for (;;) { c = gettok(&buf, &bufsize); -/* printf("gettok [%s]\n", buf); */ if (c == 0) return 0; if (isalpha(c) || c == '_') @@ -382,7 +375,7 @@ int string(void) if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL) FATAL("out of space for strings"); for (bp = buf; (c = input()) != '"'; ) { - if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, 0)) + if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string")) FATAL("out of space for string %.10s...", buf); switch (c) { case '\n': @@ -476,12 +469,13 @@ int word(char *w) int c, n; n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0])); +/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */ kp = keywords + n; if (n != -1) { /* found in table */ yylval.i = kp->sub; switch (kp->type) { /* special handling */ - case FSYSTEM: - if (safe) + case BLTIN: + if (kp->sub == FSYSTEM && safe) SYNTAX( "system is unsafe" ); RET(kp->type); case FUNC: @@ -529,7 +523,7 @@ int regexpr(void) FATAL("out of space for rex expr"); bp = buf; for ( ; ((c = input()) != '/' || openclass == 1) && c != 0; ) { - if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, 0)) + if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr")) FATAL("out of space for reg expr %.10s...", buf); if (c == '\n') { SYNTAX( "newline in regular expression %.10s...", buf ); diff --git a/usr.bin/awk/lib.c b/usr.bin/awk/lib.c index 4ec822f7c6d..afbac925c73 100644 --- a/usr.bin/awk/lib.c +++ b/usr.bin/awk/lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib.c,v 1.17 2007/09/02 15:19:31 deraadt Exp $ */ +/* $OpenBSD: lib.c,v 1.18 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -44,7 +44,7 @@ int fieldssize = RECSIZE; Cell **fldtab; /* pointers to Cells */ char inputFS[100] = " "; -#define MAXFLD 200 +#define MAXFLD 2 int nfields = MAXFLD; /* last allocated slot for $i */ int donefld; /* 1 = implies rec broken into fields */ @@ -59,15 +59,11 @@ static Cell dollar1 = { OCELL, CFLD, NULL, "", 0.0, FLD|STR|DONTFREE }; void recinit(unsigned int n) { - record = (char *) malloc(n); - fields = (char *) malloc(n); - fldtab = (Cell **) calloc((nfields+1), sizeof(Cell *)); - if (record == NULL || fields == NULL || fldtab == NULL) + if ( (record = (char *) malloc(n)) == NULL + || (fields = (char *) malloc(n+1)) == NULL + || (fldtab = (Cell **) calloc(nfields+1, sizeof(Cell *))) == NULL + || (fldtab[0] = (Cell *) malloc(sizeof(Cell))) == NULL ) FATAL("out of space for $0 and fields"); - - fldtab[0] = (Cell *) malloc(sizeof (Cell)); - if (fldtab[0] == NULL) - FATAL("out of space for fields"); *fldtab[0] = dollar0; fldtab[0]->sval = record; fldtab[0]->nval = tostring("0"); @@ -111,7 +107,8 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ { /* note: cares whether buf == record */ int c; char *buf = *pbuf; - int bufsize = *pbufsize; + uschar saveb0; + int bufsize = *pbufsize, savebufsize = bufsize; if (firsttime) { firsttime = 0; @@ -123,6 +120,7 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ donefld = 0; donerec = 1; } + saveb0 = buf[0]; buf[0] = 0; while (argno < *ARGC || infile == stdin) { dprintf( ("argno=%d, file=|%s|\n", argno, file) ); @@ -169,14 +167,15 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ infile = NULL; argno++; } + buf[0] = saveb0; *pbuf = buf; - *pbufsize = bufsize; + *pbufsize = savebufsize; return 0; /* true end of file */ } void nextfile(void) { - if (infile != stdin && infile != NULL) + if (infile != NULL && infile != stdin) fclose(infile); infile = NULL; argno++; diff --git a/usr.bin/awk/main.c b/usr.bin/awk/main.c index b0c86c5fc78..d4e52329b43 100644 --- a/usr.bin/awk/main.c +++ b/usr.bin/awk/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.14 2007/01/29 19:40:06 jmc Exp $ */ +/* $OpenBSD: main.c,v 1.15 2008/10/06 20:38:33 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 20041222"; +const char *version = "version 20071023"; #define DEBUG #include <stdio.h> @@ -35,8 +35,6 @@ const char *version = "version 20041222"; #include "awk.h" #include "ytab.h" -#define MAX_PFILE 20 - extern char **environ; extern int nfields; extern char *__progname; @@ -49,6 +47,8 @@ extern int errorflag; /* non-zero if any syntax errors; set by yyerror */ int compile_time = 2; /* for error printing: */ /* 2 = cmdline, 1 = compile, 0 = running */ +#define MAX_PFILE 20 /* max number of -f's */ + char *pfile[MAX_PFILE]; /* program filenames from -f's */ int npfile = 0; /* number of filenames */ int curpfile = 0; /* current filename */ @@ -89,6 +89,8 @@ int main(int argc, char *argv[]) FATAL("too many -f options"); if (argc <= 1) FATAL("no program filename"); + if (npfile >= MAX_PFILE - 1) + FATAL("too many -f options"); pfile[npfile++] = argv[1]; break; case 'F': /* set field separator */ @@ -111,10 +113,6 @@ int main(int argc, char *argv[]) if (argv[1][2] == '\0' && --argc > 1 && isclvar((++argv)[1])) setclvar(argv[1]); break; - case 'm': /* more memory: -mr=record, -mf=fields */ - /* no longer supported */ - WARNING("obsolete option %s ignored", argv[1]); - break; case 'd': dbg = atoi(&argv[1][2]); if (dbg == 0) diff --git a/usr.bin/awk/maketab.c b/usr.bin/awk/maketab.c index 05d15b2c0e9..01e9aff4be6 100644 --- a/usr.bin/awk/maketab.c +++ b/usr.bin/awk/maketab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: maketab.c,v 1.9 2007/04/02 08:00:07 moritz Exp $ */ +/* $OpenBSD: maketab.c,v 1.10 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -136,8 +136,7 @@ int main(int argc, char *argv[]) if (n != 4 || c != '#' || strcmp(def, "define") != 0) continue; /* not a valid #define */ if (tok < FIRSTTOKEN || tok > LASTTOKEN) { - fprintf(stderr, "maketab: funny token %d %s ignored\n", - tok, buf); + /* fprintf(stderr, "maketab: funny token %d %s ignored\n", tok, buf); */ continue; } names[tok-FIRSTTOKEN] = (char *) strdup(name); diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 9aa255c3516..8f19cf7d680 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.29 2008/06/04 14:04:42 pyr Exp $ */ +/* $OpenBSD: run.c,v 1.30 2008/10/06 20:38:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -50,19 +50,20 @@ void tempfree(Cell *p) { } */ -#ifdef _NFILE -#ifndef FOPEN_MAX -#define FOPEN_MAX _NFILE -#endif -#endif - -#ifndef FOPEN_MAX -#define FOPEN_MAX 40 /* max number of open files */ -#endif - -#ifndef RAND_MAX -#define RAND_MAX 32767 /* all that ansi guarantees */ -#endif +/* do we really need these? */ +/* #ifdef _NFILE */ +/* #ifndef FOPEN_MAX */ +/* #define FOPEN_MAX _NFILE */ +/* #endif */ +/* #endif */ +/* */ +/* #ifndef FOPEN_MAX */ +/* #define FOPEN_MAX 40 */ /* max number of open files */ +/* #endif */ +/* */ +/* #ifndef RAND_MAX */ +/* #define RAND_MAX 32767 */ /* all that ansi guarantees */ +/* #endif */ jmp_buf env; int use_arc4 = 1; @@ -115,6 +116,7 @@ int adjbuf(char **pbuf, int *psiz, int minlen, int quantum, char **pbptr, if (rminlen) minlen += quantum - rminlen; tbuf = (char *) realloc(*pbuf, minlen); + dprintf( ("adjbuf %s: %d %d (pbuf=%p, tbuf=%p)\n", whatrtn, *psiz, minlen, *pbuf, tbuf) ); if (tbuf == NULL) { if (whatrtn) FATAL("out of memory in %s", whatrtn); @@ -466,7 +468,7 @@ Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */ for (np = a[1]; np; np = np->nnext) { y = execute(np); /* subscript */ s = getsval(y); - if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0)) + if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, "array")) FATAL("out of memory for %s[%s...]", x->nval, buf); strlcat(buf, s, bufsz); if (np->nnext) @@ -513,7 +515,7 @@ Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts * for (np = a[1]; np; np = np->nnext) { y = execute(np); /* subscript */ s = getsval(y); - if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0)) + if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, "awkdelete")) FATAL("out of memory deleting %s[%s...]", x->nval, buf); strlcat(buf, s, bufsz); if (np->nnext) @@ -552,7 +554,7 @@ Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */ for (p = a[0]; p; p = p->nnext) { x = execute(p); /* expr */ s = getsval(x); - if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, 0)) + if (!adjbuf(&buf, &bufsz, strlen(buf)+strlen(s)+nsub+1, recsize, 0, "intest")) FATAL("out of memory deleting %s[%s...]", x->nval, buf); strlcat(buf, s, bufsz); tempfree(x); @@ -822,7 +824,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co if ((fmt = (char *) malloc(fmtsz)) == NULL) FATAL("out of memory in format()"); while (*s) { - adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format"); + adjbuf(&buf, &bufsize, MAXNUMSIZE+1+p-buf, recsize, &p, "format1"); if (*s != '%') { *p++ = *s++; continue; @@ -836,9 +838,9 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co fmtwd = atoi(s+1); if (fmtwd < 0) fmtwd = -fmtwd; - adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format"); + adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format2"); for (t = fmt; (*t++ = *s) != '\0'; s++) { - if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, 0)) + if (!adjbuf(&fmt, &fmtsz, MAXNUMSIZE+1+t-fmt, recsize, &t, "format3")) FATAL("format item %.30s... ran format() out of memory", os); if (isalpha((uschar)*s) && *s != 'l' && *s != 'h' && *s != 'L') break; /* the ansi panoply */ @@ -858,7 +860,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co *t = '\0'; if (fmtwd < 0) fmtwd = -fmtwd; - adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format"); + adjbuf(&buf, &bufsize, fmtwd+1+p-buf, recsize, &p, "format4"); switch (*s) { case 'f': case 'e': case 'g': case 'E': case 'G': @@ -892,7 +894,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co n = MAXNUMSIZE; if (fmtwd > n) n = fmtwd; - adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format"); + adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format5"); switch (flag) { case '?': /* unknown, so dump it too */ snprintf(p, buf + bufsize - p, "%s", fmt); @@ -900,7 +902,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co n = strlen(t); if (fmtwd > n) n = fmtwd; - adjbuf(&buf, &bufsize, 1+strlen(p)+n+p-buf, recsize, &p, "format"); + adjbuf(&buf, &bufsize, 1+strlen(p)+n+p-buf, recsize, &p, "format6"); p += strlen(p); snprintf(p, buf + bufsize - p, "%s", t); break; @@ -912,7 +914,7 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co n = strlen(t); if (fmtwd > n) n = fmtwd; - if (!adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, 0)) + if (!adjbuf(&buf, &bufsize, 1+n+p-buf, recsize, &p, "format7")) FATAL("huge string/format (%d chars) in printf %.30s... ran format() out of memory", n, t); snprintf(p, buf + bufsize - p, fmt, t); break; |