ref: c96f87d66f550ddcc92a6bf184088d4167937c0a
parent: f244847ee0654296c7bdce8c290f8faea6e101e8
author: kvik <kvik@a-b.xyz>
date: Fri Dec 4 13:36:09 EST 2020
mesg: more sensible parts list allocation strategy
--- a/mail.h
+++ b/mail.h
@@ -99,6 +99,7 @@
Mesg *body; /* best attachment to use, or nil */
Mesg **parts;
int nparts;
+ int xparts;
/* info fields */
char *from;
--- a/mesg.c
+++ b/mesg.c
@@ -158,7 +158,6 @@
sysfatal("%s read: %r", mbox.path);
m->body = nil;
- m->parts = erealloc(m->parts, (m->nparts + n)*sizeof(Mesg*));
for(i = 0; i < n; i++){
if(d[i].qid.type != QTDIR)
continue;
@@ -174,6 +173,8 @@
m->body = sub;
continue;
}
+ if(m->nparts >= m->xparts)
+ m->parts = erealloc(m->parts, (2 + m->nparts*2)*sizeof(Mesg*));
m->parts[m->nparts++] = a;
if(m->body == nil && strcmp(a->type, "text/plain") == 0)
m->body = a;