=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/awk/lex.c,v retrieving revision 1.13 retrieving revision 1.14 diff -c -r1.13 -r1.14 *** src/usr.bin/awk/lex.c 2020/06/10 21:01:32 1.13 --- src/usr.bin/awk/lex.c 2020/06/10 21:02:33 1.14 *************** *** 1,4 **** ! /* $OpenBSD: lex.c,v 1.13 2020/06/10 21:01:32 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved --- 1,4 ---- ! /* $OpenBSD: lex.c,v 1.14 2020/06/10 21:02:33 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved *************** *** 147,153 **** if (bp-buf >= sz) 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 == '-') *bp++ = c; else { --- 147,153 ---- if (bp-buf >= sz) 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 == '-') *bp++ = c; else { *************** *** 181,190 **** int yylex(void) { int c; ! static char *buf = 0; 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" ); if (sc) { sc = 0; --- 181,190 ---- int yylex(void) { int c; ! static char *buf = NULL; static int bufsize = 5; /* BUG: setting this small causes core dump! */ ! if (buf == NULL && (buf = (char *) malloc(bufsize)) == NULL) FATAL( "out of space in yylex" ); if (sc) { sc = 0; *************** *** 205,211 **** /* should this also have STR set? */ RET(NUMBER); } ! yylval.i = c; switch (c) { case '\n': /* {EOL} */ --- 205,211 ---- /* should this also have STR set? */ RET(NUMBER); } ! yylval.i = c; switch (c) { case '\n': /* {EOL} */ *************** *** 236,242 **** case '&': if (peek() == '&') { input(); RET(AND); ! } else RET('&'); case '|': if (peek() == '|') { --- 236,242 ---- case '&': if (peek() == '&') { input(); RET(AND); ! } else RET('&'); case '|': if (peek() == '|') { *************** *** 334,340 **** unputstr(buf); RET(INDIRECT); } ! case '}': if (--bracecnt < 0) SYNTAX( "extra }" ); --- 334,340 ---- unputstr(buf); RET(INDIRECT); } ! case '}': if (--bracecnt < 0) SYNTAX( "extra }" ); *************** *** 357,366 **** case '(': parencnt++; RET('('); ! case '"': return string(); /* BUG: should be like tran.c ? */ ! default: RET(c); } --- 357,366 ---- case '(': parencnt++; RET('('); ! case '"': return string(); /* BUG: should be like tran.c ? */ ! default: RET(c); } *************** *** 371,380 **** { int c, n; char *s, *bp; ! static char *buf = 0; static int bufsz = 500; ! 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, "string")) --- 371,380 ---- { int c, n; char *s, *bp; ! static char *buf = NULL; static int bufsz = 500; ! if (buf == NULL && (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, "string")) *************** *** 393,399 **** c = input(); switch (c) { case '"': *bp++ = '"'; break; ! case 'n': *bp++ = '\n'; break; case 't': *bp++ = '\t'; break; case 'f': *bp++ = '\f'; break; case 'r': *bp++ = '\r'; break; --- 393,399 ---- c = input(); switch (c) { case '"': *bp++ = '"'; break; ! case 'n': *bp++ = '\n'; break; case 't': *bp++ = '\t'; break; case 'f': *bp++ = '\f'; break; case 'r': *bp++ = '\r'; break; *************** *** 430,436 **** break; } ! default: *bp++ = c; break; } --- 430,436 ---- break; } ! default: *bp++ = c; break; } *************** *** 440,446 **** break; } } ! *bp = 0; s = tostring(buf); *bp++ = ' '; *bp++ = 0; yylval.cp = setsymtab(buf, s, 0.0, CON|STR|DONTFREE, symtab); --- 440,446 ---- break; } } ! *bp = 0; s = tostring(buf); *bp++ = ' '; *bp++ = 0; yylval.cp = setsymtab(buf, s, 0.0, CON|STR|DONTFREE, symtab); *************** *** 466,480 **** return -1; } ! int word(char *w) { Keyword *kp; 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 BLTIN: --- 466,479 ---- return -1; } ! int word(char *w) { Keyword *kp; int c, n; n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0])); if (n != -1) { /* found in table */ + kp = keywords + n; yylval.i = kp->sub; switch (kp->type) { /* special handling */ case BLTIN: *************** *** 518,528 **** int regexpr(void) { int c, openclass = 0; ! static char *buf = 0; static int bufsz = 500; char *bp; ! if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL) FATAL("out of space for rex expr"); bp = buf; for ( ; ((c = input()) != '/' || openclass == 1) && c != 0; ) { --- 517,527 ---- int regexpr(void) { int c, openclass = 0; ! static char *buf = NULL; static int bufsz = 500; char *bp; ! if (buf == NULL && (buf = (char *) malloc(bufsz)) == NULL) FATAL("out of space for rex expr"); bp = buf; for ( ; ((c = input()) != '/' || openclass == 1) && c != 0; ) { *************** *** 530,540 **** FATAL("out of space for reg expr %.10s...", buf); if (c == '\n') { *bp = '\0'; ! SYNTAX( "newline in regular expression %.10s...", buf ); unput('\n'); break; } else if (c == '\\') { ! *bp++ = '\\'; *bp++ = input(); } else { if (c == '[') --- 529,539 ---- FATAL("out of space for reg expr %.10s...", buf); if (c == '\n') { *bp = '\0'; ! SYNTAX( "newline in regular expression %.10s...", buf ); unput('\n'); break; } else if (c == '\\') { ! *bp++ = '\\'; *bp++ = input(); } else { if (c == '[') *************** *** 558,564 **** char *ep = ebuf; char yysbuf[100]; /* pushback buffer */ char *yysptr = yysbuf; ! FILE *yyin = 0; int input(void) /* get next lexical input character */ { --- 557,563 ---- char *ep = ebuf; char yysbuf[100]; /* pushback buffer */ char *yysptr = yysbuf; ! FILE *yyin = NULL; int input(void) /* get next lexical input character */ {