ref: d05b90f300b79b79eb8462aed9f649d76e432b78
parent: e87ca8d97689ad9a63c0b56d0bfbda00c56abca2
author: mischief <mischief@offblast.org>
date: Tue May 1 08:47:26 EDT 2018
libplumb: allow attributes larger than 4096, set some malloc tags
--- a/sys/src/libplumb/mesg.c
+++ b/sys/src/libplumb/mesg.c
@@ -76,15 +76,21 @@
char*
plumbpackattr(Plumbattr *attr)
{
- int n;
+ int n, l;
Plumbattr *a;
char *s, *t, *buf, *bufe;
if(attr == nil)
return nil;
- if((buf = malloc(4096)) == nil)
+ n = 0;
+ for(a=attr; a!=nil; a=a->next){
+ l = Strlen(a->value);
+ if(l > n)
+ n = l;
+ }
+ if((buf = malloc(n*2+3)) == nil)
return nil;
- bufe = buf + 4096;
+ bufe = buf + n*2+3;
n = 0;
for(a=attr; a!=nil; a=a->next)
n += Strlen(a->name) + 1 + Strlen(quote(a->value, buf, bufe)) + 1;
@@ -221,9 +227,11 @@
char *q, *v, *buf, *bufe;
int c, quoting;
- if((buf = malloc(4096)) == nil)
+ c = strlen(p) + 1;
+
+ if((buf = malloc(c)) == nil)
return nil;
- bufe = buf + 4096;
+ bufe = buf + c;
attr = prev = nil;
while(*p!='\0' && *p!='\n'){
while(*p==' ' || *p=='\t')
@@ -340,6 +348,7 @@
m = malloc(sizeof(Plumbmsg));
if(m == nil)
return nil;
+ setmalloctag(m, getcallerpc(&buf));
memset(m, 0, sizeof(Plumbmsg));
if(morep != nil)
*morep = 0;
@@ -384,7 +393,11 @@
Plumbmsg*
plumbunpack(char *buf, int n)
{
- return plumbunpackpartial(buf, n, nil);
+ Plumbmsg *m;
+ m = plumbunpackpartial(buf, n, nil);
+ if(m != nil)
+ setmalloctag(m, getcallerpc(&buf));
+ return m;
}
Plumbmsg*