}
}
- new = mem_calloc (1, sizeof (ALIAS));
+ new = p_new(ALIAS, 1);
new->self = new;
new->name = str_dup (buf);
{
state->entrylen = 0;
state->entrymax = 256;
- state->entry =
- (struct folder_file *) mem_calloc (state->entrymax,
- sizeof (struct folder_file));
+ state->entry = p_new(struct folder_file, state->entrymax);
#ifdef USE_IMAP
state->imap_browse = 0;
#endif
if (menu->tagged) {
*numfiles = menu->tagged;
- tfiles = mem_calloc (*numfiles, sizeof (char *));
+ tfiles = p_new(char *, *numfiles);
for (i = 0, j = 0; i < state.entrylen; i++) {
struct folder_file ff = state.entry[i];
char full[_POSIX_PATH_MAX];
}
else if (f[0]) { /* no tagged entries. return selected entry */
*numfiles = 1;
- tfiles = mem_calloc (*numfiles, sizeof (char *));
+ tfiles = p_new(char *, *numfiles);
mutt_expand_path (f, flen);
tfiles[0] = str_dup (f);
*files = tfiles;
}
if (i < 0) {
- tmp = mem_calloc (1, sizeof (BUFFY));
+ tmp = p_new(BUFFY, 1);
tmp->path = str_dup (buf);
tmp->magic = 0;
list_push_back (&Incoming, tmp);
static COLOR_LINE *mutt_new_color_line (void)
{
- COLOR_LINE *p = mem_calloc (1, sizeof (COLOR_LINE));
+ COLOR_LINE *p = p_new(COLOR_LINE, 1);
p->fg = p->bg = -1;
menu->data = idx;
}
- idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
+ idx[idxlen] = p_new(ATTACHPTR, 1);
if ((idx[idxlen]->content =
crypt_pgp_make_key_attachment (NULL)) != NULL) {
update_idx (menu, idx, idxlen++);
for (i = 0; i < numfiles; i++) {
char *att = files[i];
- idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
+ idx[idxlen] = p_new(ATTACHPTR, 1);
idx[idxlen]->unowned = 1;
idx[idxlen]->content = mutt_make_file_attach (att);
if (idx[idxlen]->content != NULL)
for (i = 0; i < Context->msgcount; i++) {
h = Context->hdrs[i];
if (h->tagged) {
- idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
+ idx[idxlen] = p_new(ATTACHPTR, 1);
idx[idxlen]->content = mutt_make_message_attach (Context, h, 1);
if (idx[idxlen]->content != NULL)
update_idx (menu, idx, idxlen++);
menu->data = idx;
}
- idx[idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
+ idx[idxlen] = p_new(ATTACHPTR, 1);
/* Touch the file */
if (!(fp = safe_fopen (fname, "w"))) {
mutt_error (_("Can't create file %s"), fname);
}
mx_t* compress_reg_mx (void) {
- mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ mx_t* fmt = p_new(mx_t, 1);
fmt->type = M_COMPRESSED;
fmt->local = 1;
fmt->mx_is_magic = mbox_is_magic;
debug_print (1, ("WEED is %s\n", (flags & CH_WEED) ? "Set" : "Not"));
- headers = mem_calloc (hdr_count, sizeof (char *));
+ headers = p_new(char *, hdr_count);
/* Read all the headers into the array */
while (ftello (in) < off_end) {
mutt_addrlist_to_local (a);
rfc2047_decode_adrlist (a);
- *h = mem_calloc (1, l + 2);
-
- strfcpy (*h, s, l + 1);
+ *h = p_dupstr(s, l + 1);
format_address_header (h, a);
}
/* Return a copy of KEY. */
-static crypt_key_t *crypt_copy_key (crypt_key_t * key)
+static crypt_key_t *crypt_copy_key (crypt_key_t *key)
{
crypt_key_t *k;
- k = mem_calloc (1, sizeof *k);
+ k = p_new(crypt_key_t, 1);
k->kobj = key->kobj;
gpgme_key_ref (key->kobj);
k->idx = key->idx;
n++; /* delimiter or end of string */
}
n++; /* make sure to allocate at least one byte */
- pattern = p = mem_calloc (1, n);
+ pattern = p = p_new(char, n);
for (l = list; l; l = l->next) {
s = l->data;
if (*s) {
if (!n)
goto no_pgphints;
- patarr = mem_calloc (n + 1, sizeof *patarr);
+ patarr = p_new(char *, n + 1);
for (l = hints, n = 0; l; l = l->next) {
if (l->data && *l->data)
patarr[n++] = str_dup (l->data);
#endif /* DISABLED code */
for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) {
- k = mem_calloc (1, sizeof *k);
+ k = p_new(crypt_key_t, 1);
k->kobj = key;
k->idx = idx;
k->uid = uid->uid;
flags |= KEYFLAG_CANSIGN;
for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) {
- k = mem_calloc (1, sizeof *k);
+ k = p_new(crypt_key_t, 1);
k->kobj = key;
k->idx = idx;
k->uid = uid->uid;
{
/* Save the suffix */
size_t savelen = state->lastchar - state->curpos;
- wchar_t *savebuf = mem_calloc (savelen, sizeof (wchar_t));
+ wchar_t *savebuf = p_new(wchar_t, savelen);
memcpy (savebuf, state->wbuf + state->curpos, savelen * sizeof (wchar_t));
char **tfiles;
*numfiles = 1;
- tfiles = mem_calloc (*numfiles, sizeof (char *));
+ tfiles = p_new(char *, *numfiles);
mutt_expand_path (buf, buflen);
tfiles[0] = str_dup (buf);
*files = tfiles;
return NULL;
if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB))))
- k = mem_calloc (sizeof *k, 1);
+ k = pgp_new_keyinfo();
break;
}
debug_print (2, ("user ID: %s\n", p));
- uid = mem_calloc (sizeof (pgp_uid_t), 1);
+ uid = p_new(pgp_uid_t, 1);
fix_uid (p);
uid->addr = str_dup (p);
uid->trust = trust;
((s->flags & M_DISPLAY) ? (COLS - 4) : ((COLS - 4) <
72) ? (COLS - 4) : 72);
stte.line_max = stte.WrapMargin * 4;
- stte.line = (char *) mem_calloc (1, stte.line_max + 1);
- stte.param = (char *) mem_calloc (1, STRING);
+ stte.line = p_new(char, stte.line_max + 1);
+ stte.param = p_new(char, STRING);
stte.param_len = STRING;
stte.param_used = 0;
nelem = 2;
table->nelem = nelem;
table->curnelem = 0;
- table->table = mem_calloc (nelem, sizeof (struct hash_elem *));
+ table->table = p_new(struct hash_elem *, nelem);
return table;
}
void *
mutt_hcache_open(const char *path, const char *folder)
{
- struct header_cache *h = mem_calloc(1, sizeof (HEADER_CACHE));
+ struct header_cache *h = p_new(HEADER_CACHE, 1);
int flags = VL_OWRITER | VL_OCREAT;
h->db = NULL;
h->folder = str_dup(folder);
void *mutt_hcache_open (const char *path, const char *folder)
{
- struct header_cache *h = mem_calloc (1, sizeof (HEADER_CACHE));
+ struct header_cache *h = p_new(HEADER_CACHE, 1);
int pagesize =
atoi (HeaderCachePageSize) ? atoi (HeaderCachePageSize) : 16384;
h->db = NULL;
}
if (HistSize)
- h->hist = mem_calloc (HistSize, sizeof (char *));
+ h->hist = p_new(char *, HistSize);
h->cur = 0;
h->last = 0;
}
if (ptr) {
- ptr->next = mem_calloc (1, sizeof (HOOK));
+ ptr->next = p_new(HOOK, 1);
ptr = ptr->next;
}
else
- Hooks = ptr = mem_calloc (1, sizeof (HOOK));
+ Hooks = ptr = p_new(HOOK, 1);
ptr->type = data;
ptr->command = command.data;
ptr->pattern = pat;
}
ctx->hdrmax = count;
- ctx->hdrs = mem_calloc (count, sizeof (HEADER *));
- ctx->v2r = mem_calloc (count, sizeof (int));
+ ctx->hdrs = p_new(HEADER *, count);
+ ctx->v2r = p_new(int, count);
ctx->msgcount = 0;
if (count && (imap_read_headers (idata, 0, count - 1) < 0)) {
mutt_error _("Error opening mailbox");
int started = 0;
/* make copy of header pointers to sort in natural order */
- hdrs = mem_calloc (idata->ctx->msgcount, sizeof (HEADER *));
- memcpy (hdrs, idata->ctx->hdrs, idata->ctx->msgcount * sizeof (HEADER *));
+ hdrs = p_dup(idata->ctx->hdrs, idata->ctx->msgcount);
if (Sort != SORT_ORDER) {
oldsort = Sort;
rewind (fp);
memset (&h, 0, sizeof (h));
- h.data = mem_calloc (1, sizeof (IMAP_HEADER_DATA));
+ h.data = p_new(IMAP_HEADER_DATA, 1);
do {
mfhrc = 0;
/* freshen fp, h */
rewind (fp);
memset (&h, 0, sizeof (h));
- h.data = mem_calloc (1, sizeof (IMAP_HEADER_DATA));
+ h.data = p_new(IMAP_HEADER_DATA, 1);
/* this DO loop does two things:
* 1. handles untagged messages, so we can try again on the same msg
unsigned char readonly;
memset (&newh, 0, sizeof (newh));
- newh.data = mem_calloc (1, sizeof (IMAP_HEADER_DATA));
+ newh.data = p_new(IMAP_HEADER_DATA, 1);
debug_print (2, ("parsing FLAGS\n"));
if ((s = msg_parse_flags (&newh, s)) == NULL) {
}
mx_t* imap_reg_mx (void) {
- mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ mx_t* fmt = p_new(mx_t, 1);
/* make up mx_t record... */
fmt->type = M_IMAP;
* Returns NULL on failure (no mem) */
IMAP_DATA *imap_new_idata (void)
{
- return mem_calloc (1, sizeof (IMAP_DATA));
+ return p_new(IMAP_DATA, 1);
}
/* imap_free_idata: Release and clear storage in an IMAP_DATA structure. */
if (idata->ctx)
ctx = idata->ctx;
else {
- ctx = mem_calloc (1, sizeof (CONTEXT));
+ ctx = p_new(CONTEXT, 1);
ctx->data = idata;
}
imap_check_mailbox (ctx, NULL, 1);
}
if (!((rx_t*) dst->data))
- *((rx_t**) dst->data) = mem_calloc (1, sizeof(rx_t));
+ *((rx_t**) dst->data) = p_new(rx_t, 1);
p = (rx_t*) dst->data;
}
if (!*list || last) {
- t = (LIST *) mem_calloc (1, sizeof(LIST));
+ t = p_new(LIST, 1);
t->data = str_dup (str);
if (last) {
last->next = t;
if (!tmp) {
/* create a new alias */
- tmp = (ALIAS *) mem_calloc (1, sizeof(ALIAS));
+ tmp = p_new(ALIAS, 1);
tmp->self = tmp;
tmp->name = str_dup (buf->data);
/* give the main addressbook code a chance */
static struct option_t* add_option (const char* name, const char* init,
short type, short dodup) {
- struct option_t* option = mem_calloc (1, sizeof(struct option_t));
+ struct option_t* option = p_new(struct option_t, 1);
debug_print (1, ("adding $%s\n", name));
{
struct keymap_t *p;
- p = mem_calloc (1, sizeof (struct keymap_t));
+ p = p_new(struct keymap_t, 1);
p->len = len;
p->keys = p_dup(keys, len);
return p;
#include "str.h"
list2_t* list_new (void) {
- return (mem_calloc (1, sizeof (list2_t)));
+ return p_new(list2_t, 1);
}
void list_del (list2_t** l, list_del_t* del) {
#include "exit.h"
#include "intl.h"
-void *_mem_calloc (size_t nmemb, size_t size, int line, const char* fname) {
- void *p;
-
- if (!nmemb || !size)
- return NULL;
-
- if (((size_t) - 1) / nmemb <= size) {
- exit_fatal ("mem_calloc", _("Integer overflow -- can't allocate memory!"),
- line, fname, 1);
- return (NULL);
- }
-
- if (!(p = calloc (nmemb, size))) {
- exit_fatal ("mem_calloc", _("Out of memory!"), line, fname, 1);
- return (NULL);
- }
- return p;
-}
-
void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) {
void *r;
void **p = (void **) ptr;
#include <sys/types.h>
-void* _mem_calloc (size_t, size_t, int, const char*);
void _mem_realloc (void*, size_t, int, const char*);
-
-#define mem_calloc(s,c) _mem_calloc(s,c,__LINE__,__FILE__)
#define mem_realloc(p,c) _mem_realloc(p,c,__LINE__,__FILE__)
#endif /* !_LIB_MEM_H */
#include "str.h"
rx_t *rx_compile (const char *s, int flags) {
- rx_t *pp = mem_calloc (1, sizeof (rx_t));
+ rx_t *pp = p_new(rx_t, 1);
pp->pattern = str_dup (s);
- pp->rx = mem_calloc (1, sizeof (regex_t));
+ pp->rx = p_new(regex_t, 1);
if (REGCOMP(pp->rx, NONULL (s), flags) != 0)
rx_free (&pp);
struct list_t *next;
} LIST;
-#define mutt_new_list() mem_calloc (1, sizeof (LIST))
+#define mutt_new_list() p_new(LIST, 1)
void mutt_free_list (LIST **);
LIST *mutt_copy_list (LIST *);
offset -= (sizeof MMDF_SEP - 1);
/* allocate space for the new offsets */
- newOffset = mem_calloc (ctx->msgcount - first, sizeof (struct m_update_t));
- oldOffset = mem_calloc (ctx->msgcount - first, sizeof (struct m_update_t));
+ newOffset = p_new(struct m_update_t, ctx->msgcount - first);
+ oldOffset = p_new(struct m_update_t, ctx->msgcount - first);
for (i = first, j = 0; i < ctx->msgcount; i++) {
/*
}
static mx_t* reg_mx (void) {
- mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ mx_t* fmt = p_new(mx_t, 1);
fmt->local = 1;
fmt->mx_check_empty = mbox_check_empty;
fmt->mx_is_magic = mbox_is_magic;
MUTTMENU *mutt_new_menu (void)
{
- MUTTMENU *p = (MUTTMENU *) mem_calloc (1, sizeof (MUTTMENU));
+ MUTTMENU *p = p_new(MUTTMENU, 1);
p->current = 0;
p->top = 0;
else
h->path = str_dup (fname);
- entry = mem_calloc (sizeof (struct maildir), 1);
+ entry = p_new(struct maildir, 1);
entry->h = h;
entry->header_parsed = (ctx->magic == M_MH);
#ifdef USE_INODESORT
/* routines common to maildir and mh */
static mx_t* reg_mx (void) {
- mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ mx_t* fmt = p_new(mx_t, 1);
fmt->local = 1;
fmt->mx_access = access;
fmt->mx_sync_mailbox = mh_sync_mailbox;
} SPAM_LIST;
-#define mutt_new_spam_list() mem_calloc (1, sizeof (SPAM_LIST))
+#define mutt_new_spam_list() p_new(SPAM_LIST, 1)
void mutt_free_spam_list (SPAM_LIST **);
int mutt_matches_ignore (const char *, LIST *);
p = strchr (mbx, '@');
if (!p || !p[1])
return -1;
- *user = mem_calloc ((p - mbx + 1), sizeof (mbx[0]));
- strfcpy (*user, mbx, (p - mbx + 1));
+ *user = p_dupstr(mbx[0], p - mbx);
*domain = str_dup (p + 1);
return 0;
}
{
CONNECTION *conn;
- conn = (CONNECTION *) mem_calloc (1, sizeof (CONNECTION));
+ conn = p_new(CONNECTION, 1);
conn->fd = -1;
return conn;
if (ssl_init ())
goto bail;
- ssldata = (sslsockdata *) mem_calloc (1, sizeof (sslsockdata));
+ ssldata = p_new(sslsockdata, 1);
/* the ssl_use_xxx protocol options don't apply. We must use TLS in TLS. */
if (!(ssldata->ctx = SSL_CTX_new (TLSv1_client_method ()))) {
debug_print (1, ("Error allocating SSL_CTX\n"));
if (raw_socket_open (conn) < 0)
return -1;
- data = (sslsockdata *) mem_calloc (1, sizeof (sslsockdata));
+ data = p_new(sslsockdata, 1);
conn->sockdata = data;
data->ctx = SSL_CTX_new (SSLv23_client_method ());
/* interactive check from user */
menu = mutt_new_menu ();
menu->max = 19;
- menu->dialog = (char **) mem_calloc (1, menu->max * sizeof (char *));
+ menu->dialog = p_new(char *, menu->max);
for (i = 0; i < menu->max; i++)
- menu->dialog[i] = (char *) mem_calloc (1, SHORT_STRING * sizeof (char));
+ menu->dialog[i] = p_new(char, SHORT_STRING);
row = 0;
strfcpy (menu->dialog[row], _("This certificate belongs to:"),
tlssockdata *data;
int err;
- data = (tlssockdata *) mem_calloc (1, sizeof (tlssockdata));
+ data = p_new(tlssockdata, 1);
conn->sockdata = data;
err = gnutls_certificate_allocate_credentials (&data->xcred);
if (err < 0) {
return 0;
b64_data.size = filestat.st_size + 1;
- b64_data_data = (unsigned char *) mem_calloc (1, b64_data.size);
+ b64_data_data = p_new(unsigned char, b64_data.size);
b64_data_data[b64_data.size - 1] = '\0';
b64_data.data = b64_data_data;
/* interactive check from user */
menu = mutt_new_menu ();
menu->max = 25;
- menu->dialog = (char **) mem_calloc (1, menu->max * sizeof (char *));
+ menu->dialog = p_new(char*, menu->max);
for (i = 0; i < menu->max; i++)
- menu->dialog[i] = (char *) mem_calloc (1, SHORT_STRING * sizeof (char));
+ menu->dialog[i] = p_new(char, SHORT_STRING);
row = 0;
strfcpy (menu->dialog[row], _("This certificate belongs to:"),
BODY *mutt_new_body (void)
{
- BODY *p = (BODY *) mem_calloc (1, sizeof (BODY));
+ BODY *p = p_new(BODY, 1);
p->disposition = DISPATTACH;
p->use_disp = 1;
return (NULL);
}
- msg = mem_calloc (1, sizeof (MESSAGE));
+ msg = p_new(MESSAGE, 1);
msg->magic = dest->magic;
msg->write = 1;
{
MESSAGE *msg;
- msg = mem_calloc (1, sizeof (MESSAGE));
+ msg = p_new(MESSAGE, 1);
switch (msg->magic = ctx->magic) {
case M_MBOX:
case M_MMDF:
mem_realloc (&ctx->v2r, sizeof (int) * ctx->hdrmax);
}
else {
- ctx->hdrs = mem_calloc ((ctx->hdrmax += 25), sizeof (HEADER *));
- ctx->v2r = mem_calloc (ctx->hdrmax, sizeof (int));
+ ctx->hdrs = p_new(HEADER *, (ctx->hdrmax += 25));
+ ctx->v2r = p_new(int, ctx->hdrmax);
}
for (i = ctx->msgcount; i < ctx->hdrmax; i++) {
ctx->hdrs[i] = NULL;
/* called by nntp_init(); don't call elsewhere */
mx_t* nntp_reg_mx (void) {
- mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ mx_t* fmt = p_new(mx_t, 1);
/* make up mx_t record... */
fmt->type = M_NNTP;
if (!s || !d)
return;
- l = mem_calloc (1, sizeof (LIST));
+ l = p_new(LIST, 1);
if (s->list)
s->tail->next = l;
else
len = sizeof (group);
strfcpy (group, line, len);
if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) {
- data =
- (NNTP_DATA *) mem_calloc (1, sizeof (NNTP_DATA) + str_len (group) + 1);
+ data = xmalloc(sizeof(NNTP_DATA) + str_len(group) + 1);
data->group = (char *) data + sizeof (NNTP_DATA);
strcpy (data->group, group);
data->nserv = news;
p_delete(&data->entries);
data->rc = 1;
- data->entries = mem_calloc (x * 2, sizeof (NEWSRC_ENTRY));
+ data->entries = p_new(NEWSRC_ENTRY, x * 2);
data->max = x * 2;
if (*p == ':')
}
else if (news->newsgroups) {
if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) {
- data =
- (NNTP_DATA *) mem_calloc (1,
- sizeof (NNTP_DATA) + str_len (buf) + 1);
+ data = xmalloc(sizeof(NNTP_DATA) + str_len(buf) + 1);
data->group = (char *) data + sizeof (NNTP_DATA);
strcpy (data->group, buf);
data->nserv = news;
return NULL;
}
- buf = p = mem_calloc (str_len (server) + 10, sizeof (char));
+ buf = p = p_new(char, str_len (server) + 10);
if (url_check_scheme (server) == U_UNKNOWN) {
strcpy (buf, "nntp://");
p = strchr (buf, '\0');
}
/* New newsserver */
- serv = mem_calloc (1, sizeof (NNTP_SERVER));
+ serv = p_new(NNTP_SERVER, 1);
serv->conn = conn;
serv->newsrc = str_dup (file);
serv->newsgroups = hash_create (1009);
}
if (!data->max) {
- data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
+ data->entries = p_new(NEWSRC_ENTRY, 5);
data->max = 5;
}
if (!news)
return -1;
llen = len = 10 * LONG_STRING;
- line = buf = mem_calloc (1, len);
+ line = buf = p_new(char, len);
/* we will generate full newsrc here */
for (tmp = news->list; tmp; tmp = tmp->next) {
data = (NNTP_DATA *) tmp->data;
if (!news || !news->newsgroups || !group || !*group)
return NULL;
if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) {
- data =
- (NNTP_DATA *) mem_calloc (1, sizeof (NNTP_DATA) + str_len (group) + 1);
+ data = xmalloc(sizeof(NNTP_DATA) + str_len(group) + 1);
data->group = (char *) data + sizeof (NNTP_DATA);
strcpy (data->group, group);
data->nserv = news;
!(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
return NULL;
if (!data->max) {
- data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
+ data->entries = p_new(NEWSRC_ENTRY, 5);
data->max = 5;
}
data->num = 1;
!(data = (NNTP_DATA *) hash_find (news->newsgroups, group)))
return NULL;
if (!data->max) {
- data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
+ data->entries = p_new(NEWSRC_ENTRY, 5);
data->max = 5;
}
data->num = 1;
fc.ctx = ctx;
fc.base = first;
fc.last = last;
- fc.messages = mem_calloc (last - first + 1, sizeof (unsigned short));
+ fc.messages = p_new(unsigned short, last - first + 1);
#if WANT_LISTGROUP_COMMAND
if (nntp_data->nserv->hasLISTGROUP) {
snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
/* create NNTP-specific state struct if nof found in list */
if ((nntp_data = (NNTP_DATA *) hash_find (serv->newsgroups, buf)) == NULL) {
- nntp_data = mem_calloc (1, sizeof (NNTP_DATA) + str_len (buf) + 1);
+ nntp_data = xmalloc(sizeof(NNTP_DATA) + str_len(buf) + 1);
nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
strcpy (nntp_data->group, buf);
hash_insert (serv->newsgroups, nntp_data->group, nntp_data, 0);
/* active was renumbered? */
if (last < nntp_data->lastLoaded) {
if (!nntp_data->max) {
- nntp_data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY));
+ nntp_data->entries = p_new(NEWSRC_ENTRY, 5);
nntp_data->max = 5;
}
nntp_data->lastCached = 0;
return 0;
if ((nntp_data = (NNTP_DATA *) hash_find (s->newsgroups, group)) == NULL) {
n++;
- nntp_data = mem_calloc (1, sizeof (NNTP_DATA) + str_len (group) + 1);
+ nntp_data = xmalloc(sizeof(NNTP_DATA) + str_len(group) + 1);
nntp_data->group = (char *) nntp_data + sizeof (NNTP_DATA);
strcpy (nntp_data->group, group);
nntp_data->nserv = s;
/* not much point in classifying quotes... */
if (*QuoteList == NULL) {
- class = (struct q_class_t *) mem_calloc (1, sizeof (struct q_class_t));
+ class = p_new(struct q_class_t, 1);
class->color = ColorQuote[0];
*QuoteList = class;
}
/* found shorter prefix */
if (tmp == NULL) {
/* add a node above q_list */
- tmp =
- (struct q_class_t *) mem_calloc (1, sizeof (struct q_class_t));
- tmp->prefix = (char *) mem_calloc (1, length + 1);
- strncpy (tmp->prefix, qptr, length);
+ tmp = p_new(struct q_class_t, 1);
+ tmp->prefix = p_dupstr(qptr, length);
tmp->length = length;
/* replace q_list by tmp in the top level list */
/* found shorter common prefix */
if (tmp == NULL) {
/* add a node above q_list */
- tmp = (struct q_class_t *) mem_calloc (1,
- sizeof (struct
- q_class_t));
- tmp->prefix = (char *) mem_calloc (1, length + 1);
- strncpy (tmp->prefix, qptr, length);
+ tmp = p_new(struct q_class_t, 1);
+ tmp->prefix = p_dupstr(qptr, length);
tmp->length = length;
/* replace q_list by tmp */
/* still not found so far: add it as a sibling to the current node */
if (class == NULL) {
- tmp =
- (struct q_class_t *) mem_calloc (1, sizeof (struct q_class_t));
- tmp->prefix = (char *) mem_calloc (1, length + 1);
- strncpy (tmp->prefix, qptr, length);
+ tmp = p_new(struct q_class_t, 1);
+ tmp->prefix = p_dupstr(qptr, length);
tmp->length = length;
if (ptr->down) {
if (class == NULL) {
/* not found so far: add it as a top level class */
- class = (struct q_class_t *) mem_calloc (1, sizeof (struct q_class_t));
- class->prefix = (char *) mem_calloc (1, length + 1);
- strncpy (class->prefix, qptr, length);
+ class = p_new(struct q_class_t, 1);
+ class->prefix = p_dupstr(qptr, length);
class->length = length;
new_class_color (class, q_level);
pgp_uid_t **lp = &l;
for (; up; up = up->next) {
- *lp = mem_calloc (1, sizeof (pgp_uid_t));
+ *lp = p_new(pgp_uid_t, 1);
(*lp)->trust = up->trust;
(*lp)->flags = up->flags;
(*lp)->addr = str_dup (up->addr);
void pgp_free_key (pgp_key_t * kpp);
-#define pgp_new_keyinfo() mem_calloc (sizeof *((pgp_key_t)0), 1)
+#define pgp_new_keyinfo() xmalloc(sizeof *((pgp_key_t)0))
#endif /* CRYPT_BACKEND_CLASSIC_PGP */
case PT_SIG:
{
if (lsig) {
- pgp_sig_t *signature = mem_calloc (sizeof (pgp_sig_t), 1);
+ pgp_sig_t *signature = p_new(pgp_sig_t, 1);
*lsig = signature;
lsig = &signature->next;
chr = p_dupstr(buff + 1, l - 1);
- *addr = uid = mem_calloc (1, sizeof (pgp_uid_t)); /* XXX */
+ *addr = uid = p_new(pgp_uid_t, 1); /* XXX */
uid->addr = chr;
uid->parent = p;
uid->trust = 0;
}
mx_t* pop_reg_mx (void) {
- mx_t* fmt = mem_calloc (1, sizeof (mx_t));
+ mx_t* fmt = p_new(mx_t, 1);
/* make up mx_t record... */
fmt->type = M_POP;
p_delete(&ctx->path);
ctx->path = str_dup (buf);
- pop_data = mem_calloc (1, sizeof (POP_DATA));
+ pop_data = p_new(POP_DATA, 1);
pop_data->conn = conn;
ctx->data = pop_data;
return;
}
- url = p = mem_calloc (strlen (PopHost) + 7, sizeof (char));
+ url = p = p_new(char, strlen (PopHost) + 7);
if (url_check_scheme (PopHost) == U_UNKNOWN) {
strcpy (url, "pop://"); /* __STRCPY_CHECKED__ */
p = strchr (url, '\0');
if (!conn)
return;
- pop_data = mem_calloc (1, sizeof (POP_DATA));
+ pop_data = p_new(POP_DATA, 1);
pop_data->conn = conn;
if (pop_open_connection (pop_data) < 0) {
#define mutt_system(x) _mutt_system(x,0)
int _mutt_system (const char *, int);
-#define mutt_new_parameter() mem_calloc (1, sizeof (PARAMETER))
-#define mutt_new_header() mem_calloc (1, sizeof (HEADER))
-#define mutt_new_envelope() mem_calloc (1, sizeof (ENVELOPE))
-#define mutt_new_enter_state() mem_calloc (1, sizeof (ENTER_STATE))
+#define mutt_new_parameter() p_new(PARAMETER, 1)
+#define mutt_new_header() p_new(HEADER, 1)
+#define mutt_new_envelope() p_new(ENVELOPE, 1)
+#define mutt_new_enter_state() p_new(ENTER_STATE, 1)
typedef const char *format_t (char *, size_t, char, const char *,
const char *, const char *, const char *,
(option (OPTLOCALES) ? 0 : (wc >= 0xa0)))
#endif
-#define new_pattern() mem_calloc(1, sizeof (pattern_t))
+#define new_pattern() p_new(pattern_t, 1)
int mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
CONTEXT * ctx, HEADER * h);
if (first == NULL) {
FirstColumn = 0;
SecondColumn = 0;
- first = (QUERY *) mem_calloc (1, sizeof (QUERY));
+ first = p_new(QUERY, 1);
cur = first;
}
else {
- cur->next = (QUERY *) mem_calloc (1, sizeof (QUERY));
+ cur->next = p_new(QUERY, 1);
cur = cur->next;
}
for (queryp = results; queryp; queryp = queryp->next)
menu->max++;
- menu->data = QueryTable =
- (ENTRY *) mem_calloc (menu->max, sizeof (ENTRY));
+ menu->data = QueryTable = p_new(ENTRY, menu->max);
for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
QueryTable[i].data = queryp;
menu->max++;
if (op == OP_QUERY) {
- menu->data = QueryTable =
- (ENTRY *) mem_calloc (menu->max, sizeof (ENTRY));
+ menu->data = QueryTable = p_new(ENTRY, menu->max);
for (i = 0, queryp = results; queryp;
queryp = queryp->next, i++)
}
else {
if (!idx[*idxlen])
- idx[*idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR));
+ idx[*idxlen] = p_new(ATTACHPTR, 1);
new = idx[(*idxlen)++];
new->content = m;
static REMAILER *mix_new_remailer (void)
{
- return mem_calloc (1, sizeof (REMAILER));
+ return p_new(REMAILER, 1);
}
static void mix_free_remailer (REMAILER ** r)
*redraw = REDRAW_FULL;
- chain = mem_calloc (sizeof (MIXCHAIN), 1);
+ chain = p_new(MIXCHAIN, 1);
for (p = *chainp; p; p = p->next)
mix_chain_add (chain, (char *) p->data, type2_list);
rfc1524_entry *rfc1524_new_entry (void)
{
- return (rfc1524_entry *) mem_calloc (1, sizeof (rfc1524_entry));
+ return p_new(rfc1524_entry, 1);
}
void rfc1524_free_entry (rfc1524_entry ** entry)
static struct rfc2231_parameter *rfc2231_new_parameter (void)
{
- return mem_calloc (sizeof (struct rfc2231_parameter), 1);
+ return p_new(struct rfc2231_parameter, 1);
}
static void rfc2231_free_parameter (struct rfc2231_parameter **p)
p_delete(&pattern);
return (-1);
}
- ptr = mem_calloc (1, sizeof (SCORE));
+ ptr = p_new(SCORE, 1);
if (last)
last->next = ptr;
else
if (cd1 == (iconv_t) (-1))
return -1;
- cd = mem_calloc (ncodes, sizeof (iconv_t));
- score = mem_calloc (ncodes, sizeof (size_t));
- states = mem_calloc (ncodes, sizeof (CONTENT_STATE));
- infos = mem_calloc (ncodes, sizeof (CONTENT));
+ cd = p_new(iconv_t, ncodes);
+ score = p_new(size_t, ncodes);
+ states = p_new(CONTENT_STATE, ncodes);
+ infos = p_new(CONTENT, ncodes);
for (i = 0; i < ncodes; i++)
if (ascii_strcasecmp (tocodes[i], "UTF-8"))
return (NULL);
}
- info = mem_calloc (1, sizeof (CONTENT));
+ info = p_new(CONTENT, 1);
memset (&state, 0, sizeof (state));
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) {
}
/* Read Entries */
cur = 0;
- Table = mem_calloc (cert_num, sizeof (smime_id));
+ Table = p_new(smime_id, cert_num);
while (!feof (index)) {
numFields =
fscanf (index, MUTT_FORMAT (STRING) " %x.%i " MUTT_FORMAT (STRING),
if (copy && buffer && num) {
(*num) = count;
- *buffer = mem_calloc (sizeof (char *), count);
+ *buffer = p_new(char *, count);
count = 0;
rewind (fpout);
while ((fgets (email, sizeof (email), fpout))) {
*(email + str_len (email) - 1) = '\0';
- (*buffer)[count] = mem_calloc (1, str_len (email) + 1);
- strncpy ((*buffer)[count], email, str_len (email));
+ (*buffer)[count] = p_dupstr(email, str_len(email));
count++;
}
}
break;
}
if (!curlist || rc > 0) {
- newlist = mem_calloc (1, sizeof (LIST));
+ newlist = p_new(LIST, 1);
newlist->data = env->real_subj;
if (oldlist) {
newlist->next = oldlist->next;
top = thread;
- array = mem_calloc ((array_size = 256), sizeof (THREAD *));
+ array = p_new(THREAD *, (array_size = 256));
while (1) {
if (init || !thread->sort_key) {
thread->sort_key = NULL;
else {
new = (option (OPTDUPTHREADS) ? thread : NULL);
- thread = mem_calloc (1, sizeof (THREAD));
+ thread = p_new(THREAD, 1);
thread->message = cur;
thread->check_subject = 1;
cur->thread = thread;
break;
if ((new = hash_find (ctx->thread_hash, ref->data)) == NULL) {
- new = mem_calloc (1, sizeof (THREAD));
+ new = p_new(THREAD, 1);
hash_insert (ctx->thread_hash, ref->data, new, 1);
}
else {