9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] awk split(a[1], a)
@ 2012-12-10  7:13 cinap_lenrek
  2012-12-10  8:20 ` cinap_lenrek
  2012-12-10 13:13 ` erik quanstrom
  0 siblings, 2 replies; 11+ messages in thread
From: cinap_lenrek @ 2012-12-10  7:13 UTC (permalink / raw)
  To: 9fans

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



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-12-13  3:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-10  7:13 [9fans] awk split(a[1], a) cinap_lenrek
2012-12-10  8:20 ` cinap_lenrek
2012-12-10 13:13 ` erik quanstrom
2012-12-12 21:33   ` David du Colombier
2012-12-12 21:39     ` erik quanstrom
2012-12-12 22:24       ` cinap_lenrek
2012-12-12 22:31         ` erik quanstrom
2012-12-12 22:38           ` cinap_lenrek
2012-12-13  3:22         ` erik quanstrom
2012-12-13  3:35           ` cinap_lenrek
2012-12-13  3:37             ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).