diff options
author | Elliott Hughes <enh@google.com> | 2022-06-10 12:48:54 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2022-06-10 12:48:54 -0700 |
commit | 9b4616b495bf1d1c9ed5cb0c6cf30aeac88ac5a6 (patch) | |
tree | 9a6994b0f176a0657d899c84ea2ef3266e029d13 | |
parent | aec3637c7510dc613eb378a1c54f29fd03d987ed (diff) | |
parent | b92d8cecd132ce8e02a373e28dd42e6be34d3d59 (diff) | |
download | one-true-awk-9b4616b495bf1d1c9ed5cb0c6cf30aeac88ac5a6.tar.gz |
Upgrade one-true-awk to b92d8cecd132ce8e02a373e28dd42e6be34d3d59
Test: make
Change-Id: I51149eca18f8461f5931d042e9e2ef23aaf61e08
-rw-r--r-- | FIXES | 17 | ||||
-rw-r--r-- | METADATA | 6 | ||||
-rw-r--r-- | lib.c | 4 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | makefile | 1 | ||||
-rw-r--r-- | run.c | 9 | ||||
-rwxr-xr-x | testdir/T.argv | 6 | ||||
-rw-r--r-- | tran.c | 15 |
8 files changed, 36 insertions, 24 deletions
@@ -25,6 +25,23 @@ THIS SOFTWARE. This file lists all bug fixes, changes, etc., made since the AWK book was sent to the printers in August, 1987. + +May 23, 2022: + Memory leak when assigning a string to some of the built-in + variables. allocated string erroneously marked DONTFREE. + Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>. + +Mar 14, 2022: + Historic bug: command-line "name=value" assignment had been + truncating its entry in ARGV. (circa 1989) Thanks to + Miguel Pineiro Jr. <mpj@pineiro.cc>. + +Mar 3, 2022: + Fixed file management memory leak that appears to have been + there since the files array was first initialized with stdin, + stdout, and stderr (circa 1992). Thanks to Miguel Pineiro Jr. + <mpj@pineiro.cc>. + December 8, 2021: The error handling in closefile and closeall was mangled. Long standing warnings had been made fatal and some fatal errors went @@ -5,11 +5,11 @@ third_party { type: GIT value: "https://github.com/onetrueawk/awk.git" } - version: "075624a72ab15649f255a3a1dabfd7cb7766a7d7" + version: "b92d8cecd132ce8e02a373e28dd42e6be34d3d59" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 7 + month: 6 + day: 10 } } @@ -297,12 +297,13 @@ char *getargv(int n) /* get ARGV[n] */ void setclvar(char *s) /* set var=value from s */ { - char *p; + char *e, *p; Cell *q; double result; for (p=s; *p != '='; p++) ; + e = p; *p++ = 0; p = qstring(p, '\0'); q = setsymtab(s, p, 0.0, STR, symtab); @@ -312,6 +313,7 @@ void setclvar(char *s) /* set var=value from s */ q->tval |= NUM; } DPRINTF("command line set %s to |%s|\n", s, p); + *e = '='; } @@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ****************************************************************/ -const char *version = "version 20211208"; +const char *version = "version 20220530"; #define DEBUG #include <stdio.h> @@ -36,6 +36,7 @@ CC = $(HOSTCC) # change this is cross-compiling. # By fiat, to make our lives easier, yacc is now defined to be bison. # If you want something else, you're on your own. +# YACC = yacc -d -b awkgram YACC = bison -d OFILES = b.o main.o parse.o proctab.o tran.o lib.o run.o lex.o @@ -1780,13 +1780,13 @@ static void stdinit(void) /* in case stdin, etc., are not constants */ if (files == NULL) FATAL("can't allocate file memory for %zu files", nfiles); files[0].fp = stdin; - files[0].fname = "/dev/stdin"; + files[0].fname = tostring("/dev/stdin"); files[0].mode = LT; files[1].fp = stdout; - files[1].fname = "/dev/stdout"; + files[1].fname = tostring("/dev/stdout"); files[1].mode = GT; files[2].fp = stderr; - files[2].fname = "/dev/stderr"; + files[2].fname = tostring("/dev/stderr"); files[2].mode = GT; } @@ -1890,8 +1890,7 @@ Cell *closefile(Node **a, int n) stat = fclose(files[i].fp) == EOF; if (stat) WARNING("i/o error occurred closing %s", files[i].fname); - if (i > 2) /* don't do /dev/std... */ - xfree(files[i].fname); + xfree(files[i].fname); files[i].fname = NULL; /* watch out for ref thru this */ files[i].fp = NULL; break; diff --git a/testdir/T.argv b/testdir/T.argv index b9a67ef..55e2754 100755 --- a/testdir/T.argv +++ b/testdir/T.argv @@ -97,6 +97,12 @@ echo '111 $awk '{print L $0}' L=11 foo0 L=22 foo0 >foo2 diff foo1 foo2 || echo 'BAD: T.argv (L=11 L=22)' +echo >foo0 +echo 'name=value +name=value' >foo1 +$awk 'BEGIN { print ARGV[1] } { print ARGV[1] }' name=value foo0 >foo2 +diff foo1 foo2 || echo 'BAD: T.argv assignment operand modified' + echo 3.345 >foo1 $awk 'BEGIN { print ARGV[1] + ARGV[2]}' 1 2.345 >foo2 diff foo1 foo2 || echo 'BAD: T.argv (ARGV[1] + ARGV[2])' @@ -70,18 +70,6 @@ Cell *literal0; extern Cell **fldtab; -static void -setfree(Cell *vp) -{ - if (&vp->sval == FS || &vp->sval == RS || - &vp->sval == OFS || &vp->sval == ORS || - &vp->sval == OFMT || &vp->sval == CONVFMT || - &vp->sval == FILENAME || &vp->sval == SUBSEP) - vp->tval |= DONTFREE; - else - vp->tval &= ~DONTFREE; -} - void syminit(void) /* initialize symbol table with builtin vars */ { literal0 = setsymtab("0", "0", 0.0, NUM|STR|CON|DONTFREE, symtab); @@ -377,10 +365,9 @@ char *setsval(Cell *vp, const char *s) /* set string val of a Cell */ t = s ? tostring(s) : tostring(""); /* in case it's self-assign */ if (freeable(vp)) xfree(vp->sval); - vp->tval &= ~(NUM|CONVC|CONVO); + vp->tval &= ~(NUM|DONTFREE|CONVC|CONVO); vp->tval |= STR; vp->fmt = NULL; - setfree(vp); DPRINTF("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n", (void*)vp, NN(vp->nval), t, (void*)t, vp->tval, donerec, donefld); vp->sval = t; |