code: plan9front

Download patch

ref: f332cf05579e82b213944a331c7b4f37f88f2587
parent: 60f9467c011394d8ebeebed15733ebd0b58a10d0
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Aug 13 18:12:20 EDT 2022

dtracy: correctly look up aggregate keys

the ANode struct contains a variable sized buffer for the key,
however when we created and copied the aggregate, we used struct
assignment to initialize the node. the struct assignment only
knows about the fixed size portion of the struct, and did not
copy the key, which mean that key lookups would fail, and we would
insert a new value into the aggregation every time, both leaking
the memory and producng incorrect results.

--- a/sys/src/cmd/dtracy/agg.c
+++ b/sys/src/cmd/dtracy/agg.c
@@ -93,7 +93,7 @@
 		np = (ANode *) avllookup(tp, key, 0);
 		if(np == nil){
 			np = emalloc(sizeof(ANode) - 1 + a->keysize);
-			*np = *key;
+			memcpy(np, key, sizeof(ANode) - 1 + a->keysize);
 			createrecord(a->type, np, (s64int*)&p[8+a->keysize]);
 			avlinsert(tp, np);
 		}else