aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2022-06-10 22:22:42 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-06-10 22:22:42 +0000
commit2571c6713a47745a0b6783e69def676146a62ae0 (patch)
tree9a6994b0f176a0657d899c84ea2ef3266e029d13
parent1014a2c31585d55b0b7f897a7603374a39f475ee (diff)
parent6b6938702243f31affda7c19b2d0c566493b32ee (diff)
downloadone-true-awk-2571c6713a47745a0b6783e69def676146a62ae0.tar.gz
Upgrade one-true-awk to b92d8cecd132ce8e02a373e28dd42e6be34d3d59 am: 9b4616b495 am: 6b69387022
Original change: https://android-review.googlesource.com/c/platform/external/one-true-awk/+/2120428 Change-Id: Ie37f2f8caefb903943d94c9b937efcb6c970aca2 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--FIXES17
-rw-r--r--METADATA6
-rw-r--r--lib.c4
-rw-r--r--main.c2
-rw-r--r--makefile1
-rw-r--r--run.c9
-rwxr-xr-xtestdir/T.argv6
-rw-r--r--tran.c15
8 files changed, 36 insertions, 24 deletions
diff --git a/FIXES b/FIXES
index 8e49fe9..e5ee5cf 100644
--- a/FIXES
+++ b/FIXES
@@ -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
diff --git a/METADATA b/METADATA
index 052f466..4db70cc 100644
--- a/METADATA
+++ b/METADATA
@@ -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
}
}
diff --git a/lib.c b/lib.c
index c7709f7..af23554 100644
--- a/lib.c
+++ b/lib.c
@@ -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 = '=';
}
diff --git a/main.c b/main.c
index 986f1a3..187ba99 100644
--- a/main.c
+++ b/main.c
@@ -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>
diff --git a/makefile b/makefile
index 9ceaaad..df966ef 100644
--- a/makefile
+++ b/makefile
@@ -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
diff --git a/run.c b/run.c
index f5c19a1..df616fc 100644
--- a/run.c
+++ b/run.c
@@ -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])'
diff --git a/tran.c b/tran.c
index c6ae890..c396db4 100644
--- a/tran.c
+++ b/tran.c
@@ -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;