/* Call free(3), if ptr isn't NULL. */
void mh_xfree(void *ptr);
+/* Set p to point to newly allocated, uninitialised, memory. */
+#define NEW(p) ((p) = mh_xmalloc(sizeof *(p)))
+
/* Set p to point to newly allocated, zeroed, memory. */
#define NEW0(p) ((p) = mh_xcalloc(1, sizeof *(p)))
*/
charstring_t
charstring_create (size_t max) {
- charstring_t s = mh_xmalloc (sizeof *s);
+ charstring_t s;
+ NEW(s);
s->max = NMH_MAX_CHARWIDTH * (max ? max : CHARSTRING_DEFAULT_SIZE);
s->cur = s->buffer = mh_xmalloc (s->max);
s->chars = 0;
charstring_t
charstring_copy (const charstring_t src) {
const size_t num = src->cur - src->buffer;
- charstring_t s = mh_xmalloc (sizeof *s);
+ charstring_t s;
+ NEW(s);
s->max = src->max;
s->buffer = mh_xmalloc (s->max);
memcpy (s->buffer, src->buffer, num);
* If path is given, create a minimal profile/context list
*/
if (path) {
- m_defs = (struct node *) mh_xmalloc (sizeof(*np));
-
- np = m_defs;
+ NEW(np);
+ m_defs = np;
if (!(np->n_name = strdup ("Path"))) {
advise (NULL, "strdup failed");
return -1;
* If list is empty, allocate head of profile/context list.
*/
if (!m_defs) {
- m_defs = (struct node *) mh_xmalloc (sizeof(*np));
-
- np = m_defs;
+ NEW(np);
+ m_defs = np;
np->n_name = getcpy (key);
np->n_field = getcpy (value);
np->n_context = 1;
/*
* Else add this new entry at the end
*/
- np->n_next = (struct node *) mh_xmalloc (sizeof(*np));
-
+ NEW(np->n_next);
np = np->n_next;
np->n_name = getcpy (key);
np->n_field = getcpy (value);
void
crawl_folders (char *dir, crawl_callback_t *callback, void *baton)
{
- struct crawl_context *crawl = mh_xmalloc (sizeof(*crawl));
+ struct crawl_context *crawl;
+ NEW(crawl);
crawl->max = CRAWL_NUMFOLDERS;
crawl->total = crawl->start = crawl->foldp = 0;
crawl->folders = mh_xmalloc (crawl->max * sizeof(*crawl->folders));
}
/* Allocate the main structure for folder information */
- mp = (struct msgs *) mh_xmalloc ((size_t) sizeof(*mp));
-
+ NEW(mp);
clear_folder_flags (mp);
mp->foldpath = name;
mp->lowmsg = 0;
struct lock *lp;
size_t len;
- lp = (struct lock *) mh_xmalloc (sizeof(*lp));
+ NEW(lp);
len = strlen(curlock) + 1;
lp->l_fd = fd;
m_getfld_state_init (m_getfld_state_t *gstate, FILE *iob) {
m_getfld_state_t s;
- s = *gstate = (m_getfld_state_t) mh_xmalloc(sizeof (struct m_getfld_state));
+ NEW(s);
+ *gstate = s;
s->readpos = s->end = s->msg_buf;
s->bytes_read = s->total_bytes_read = 0;
s->last_caller_pos = s->last_internal_pos = 0;
netsec_context *
netsec_init(void)
{
- netsec_context *nsc = mh_xmalloc(sizeof(*nsc));
+ netsec_context *nsc;
+ NEW(nsc);
nsc->ns_readfd = -1;
nsc->ns_writefd = -1;
nsc->ns_snoop = 0;
*/
if (nsc->sasl_creds == NULL) {
- nsc->sasl_creds = mh_xmalloc(sizeof(*nsc->sasl_creds));
+ NEW(nsc->sasl_creds);
nsc->sasl_creds->user = NULL;
nsc->sasl_creds->password = NULL;
}
return SASL_BADPARAM;
if (nsc->sasl_creds == NULL) {
- nsc->sasl_creds = mh_xmalloc(sizeof(*nsc->sasl_creds));
+ NEW(nsc->sasl_creds);
nsc->sasl_creds->user = NULL;
nsc->sasl_creds->password = NULL;
}
boolean
mh_oauth_new(mh_oauth_ctx **result, const char *svc_name)
{
- mh_oauth_ctx *ctx = *result = mh_xmalloc(sizeof *ctx);
+ mh_oauth_ctx *ctx;
+ NEW(ctx);
+ *result = ctx;
ctx->curl = NULL;
ctx->log = NULL;
return NULL;
}
- result = mh_xmalloc(sizeof *result);
+ NEW(result);
result->ctx = ctx;
result->access_token = result->refresh_token = NULL;
int state;
m_getfld_state_t getfld_ctx = 0;
- struct user_creds *user_creds = mh_xmalloc(sizeof *user_creds);
+ struct user_creds *user_creds;
+ NEW(user_creds);
user_creds->alloc = 4;
user_creds->len = 0;
user_creds->creds = mh_xmalloc(user_creds->alloc * sizeof *user_creds->creds);
switch (state = m_getfld (&gstate, name, field, &fieldsz, ib)) {
case FLD:
case FLDPLUS:
- np = (struct node *) mh_xmalloc (sizeof(*np));
+ NEW(np);
*npp = np;
*(npp = &np->n_next) = NULL;
np->n_name = getcpy (name);
void
add_profile_entry (const char *key, const char *value) {
- struct node *newnode = (struct node *) mh_xmalloc (sizeof *newnode);
+ struct node *newnode;
/* This inserts the new node at the beginning of m_defs because
that doesn't require traversing it or checking to see if it's
empty. */
+ NEW(newnode);
newnode->n_name = getcpy (key);
newnode->n_field = getcpy (value);
newnode->n_context = 0;
bvector_t
bvector_create (size_t init_size) {
- bvector_t vec = mh_xmalloc (sizeof *vec);
- size_t bytes = BVEC_BYTES (vec, init_size ? init_size : VEC_INIT_SIZE);
+ bvector_t vec;
+ size_t bytes;
+
+ NEW(vec);
+ bytes = BVEC_BYTES (vec, init_size ? init_size : VEC_INIT_SIZE);
vec->bits = mh_xmalloc (bytes);
memset (vec->bits, 0, bytes);
svector_t
svector_create (size_t init_size) {
- svector_t vec = mh_xmalloc (sizeof *vec);
+ svector_t vec;
size_t bytes;
+ NEW(vec);
vec->maxsize = init_size ? init_size : VEC_INIT_SIZE;
bytes = vec->maxsize * sizeof (char *);
vec->strs = mh_xmalloc (bytes);
ivector_t
ivector_create (size_t init_size) {
- ivector_t vec = mh_xmalloc (sizeof *vec);
+ ivector_t vec;
size_t bytes;
+ NEW(vec);
vec->maxsize = init_size ? init_size : VEC_INIT_SIZE;
bytes = vec->maxsize * sizeof (int);
vec->ints = mh_xmalloc (bytes);
if (!strcmp (pp, ad->ad_text))
return;
- ad = (struct adr *) mh_xmalloc (sizeof(*ad));
+ NEW(ad);
ad->ad_text = getcpy (pp);
ad->ad_local = strchr(pp, '@') == NULL && strchr(pp, '!') == NULL;
ad->ad_next = NULL;
{
register struct aka *p;
- p = (struct aka *) mh_xmalloc (sizeof(*p));
-
+ NEW(p);
p->ak_name = getcpy (id);
p->ak_visible = 0;
p->ak_addr = NULL;
{
register struct home *p;
- p = (struct home *) mh_xmalloc (sizeof(*p));
-
+ NEW(p);
p->h_name = getcpy (pw->pw_name);
p->h_uid = pw->pw_uid;
p->h_gid = pw->pw_gid;
if (trace) {
struct trace_context *ctx;
- ctx = mh_xmalloc(sizeof(*ctx));
+ NEW(ctx);
ctx->num = -1;
ctx->str = dummy;
ctx->outbuf = getcpy(NULL);
/*
* Add some initial elements to the profile/context list
*/
- m_defs = (struct node *) mh_xmalloc (sizeof *np);
- np = m_defs;
+ NEW(np);
+ m_defs = np;
np->n_name = getcpy ("Path");
np->n_field = getcpy (pathname);
np->n_context = 0;
goto finish_field;
}
- entry = mh_xmalloc(sizeof(*entry));
+ NEW(entry);
entry->filename = getcpy(s);
entry->next = NULL;
free(vp);
if (! strncasecmp (name, ENCODING_FIELD,
strlen (ENCODING_FIELD))) {
char *prefix = "Nmh-REPLACED-INVALID-";
- HF h = mh_xmalloc (sizeof *h);
+ HF h;
+ NEW(h);
h->name = add (hf->name, NULL);
h->hf_encoding = hf->hf_encoding;
h->next = hf->next;
static int
insert_new_text_plain_part (CT ct, int new_subpart_number, CT parent) {
struct multipart *mp = (struct multipart *) parent->c_ctparams;
- struct part *new_part = mh_xmalloc (sizeof *new_part);
+ struct part *new_part;
+ NEW(new_part);
if ((new_part->mp_part = build_text_plain_part (ct))) {
char buffer[16];
snprintf (buffer, sizeof buffer, "%d", new_subpart_number);
add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
"boundary", boundary, 0);
- p = (struct part *) mh_xmalloc (sizeof *p);
- p->mp_next = (struct part *) mh_xmalloc (sizeof *p->mp_next);
+ NEW(p);
+ NEW(p->mp_next);
p->mp_next->mp_next = NULL;
p->mp_next->mp_part = first_alt;
HF hp;
/* allocate header field structure */
- hp = mh_xmalloc (sizeof(*hp));
+ NEW(hp);
/* link data into header structure */
hp->name = name;
}
if (pp == NULL) {
- pp = mh_xmalloc(sizeof(*pp));
+ NEW(pp);
memset(pp, 0, sizeof(*pp));
pp->name = nameptr;
pp->next = phead;
* Insert this into the section linked list
*/
- sp = mh_xmalloc(sizeof(*sp));
+ NEW(sp);
memset(sp, 0, sizeof(*sp));
sp->value = valptr;
sp->index = index;
PM
add_param(PM *first, PM *last, char *name, char *value, int nocopy)
{
- PM pm = mh_xmalloc(sizeof(*pm));
+ PM pm;
+ NEW(pm);
memset(pm, 0, sizeof(*pm));
-
pm->pm_name = nocopy ? name : getcpy(name);
pm->pm_value = nocopy ? value : getcpy(value);
dispo_comp = comp;
} else if (strncasecmp(comp->c_name, "ctype-", 6) == 0 &&
strlen(comp->c_name) > 6) {
- pc_entry = mh_xmalloc(sizeof(*pc_entry));
+ NEW(pc_entry);
pc_entry->param = getcpy(comp->c_name + 6);
pc_entry->comp = comp;
pc_entry->next = ctype_pc_list;
ctype_pc_list = pc_entry;
} else if (strncasecmp(comp->c_name, "cdispo-", 7) == 0 &&
strlen(comp->c_name) > 7) {
- pc_entry = mh_xmalloc(sizeof(*pc_entry));
+ NEW(pc_entry);
pc_entry->param = getcpy(comp->c_name + 7);
pc_entry->comp = comp;
pc_entry->next = dispo_pc_list;
mhstoreinfo_t
mhstoreinfo_create (CT *ct, char *pwd, const char *csw, int asw, int vsw) {
- mhstoreinfo_t info = mh_xmalloc (sizeof *info);
+ mhstoreinfo_t info;
+ NEW(info);
info->cts = ct;
info->cwd = pwd;
info->autosw = asw;
if (is_cur || msgnums != NULL) {
if (*b->first == NULL) {
- *b->first = b->node = mh_xmalloc(sizeof(*b->node));
+ NEW(b->node);
+ *b->first = b->node;
} else {
- b->node->n_next = mh_xmalloc(sizeof(*b->node));
+ NEW(b->node->n_next);
b->node = b->node->n_next;
}
b->node->n_name = folder;
* local part.
*/
while ((cp = getname (str))) {
- struct adr_node *adr_nodep = mh_xmalloc (sizeof *adr_nodep);
+ struct adr_node *adr_nodep;
char error[BUFSIZ];
struct mailname *mp;
+ NEW(adr_nodep);
adr_nodep->adr = strdup (cp);
adr_nodep->escape_local_part = 0;
adr_nodep->fixed = 0;