c***@gmx.de
2012-12-10 07:13:11 UTC
theres a bug in awk's split function. split depopules
the array a, accidently freeing a[1] (y). this doesnt show
up with ape's memory allocator but with plan9's pool
allocator or by modifying freesymtab() to XXX out
the strings before freeing one gets surprising results
like:
awk 'BEGIN{a[1]="a b";print split(a[1],a),a[1],a[2]}'
1 XXX
diff -r c0da82ea3510 sys/src/cmd/awk/run.c
--- a/sys/src/cmd/awk/run.c Sat Dec 08 09:23:05 2012 +0100
+++ b/sys/src/cmd/awk/run.c Mon Dec 10 07:17:56 2012 +0100
@@ -1213,7 +1213,9 @@
FATAL("illegal type of split");
sep = *fs;
ap = execute(a[1]); /* array name */
+ y->tval |= DONTFREE; /* split(a[x], a); */
freesymtab(ap);
+ y->tval &= ~DONTFREE;
dprintf( ("split: s=|%s|, a=%s, sep=|%s|\n", s, ap->nval, fs) );
ap->tval &= ~STR;
ap->tval |= ARR;
--
cinap
the array a, accidently freeing a[1] (y). this doesnt show
up with ape's memory allocator but with plan9's pool
allocator or by modifying freesymtab() to XXX out
the strings before freeing one gets surprising results
like:
awk 'BEGIN{a[1]="a b";print split(a[1],a),a[1],a[2]}'
1 XXX
diff -r c0da82ea3510 sys/src/cmd/awk/run.c
--- a/sys/src/cmd/awk/run.c Sat Dec 08 09:23:05 2012 +0100
+++ b/sys/src/cmd/awk/run.c Mon Dec 10 07:17:56 2012 +0100
@@ -1213,7 +1213,9 @@
FATAL("illegal type of split");
sep = *fs;
ap = execute(a[1]); /* array name */
+ y->tval |= DONTFREE; /* split(a[x], a); */
freesymtab(ap);
+ y->tval &= ~DONTFREE;
dprintf( ("split: s=|%s|, a=%s, sep=|%s|\n", s, ap->nval, fs) );
ap->tval &= ~STR;
ap->tval |= ARR;
--
cinap