From: Pierre Habouzit Date: Sat, 28 Oct 2006 22:55:24 +0000 (+0200) Subject: mem_calloc -> p_new X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=b3cb6ed8d36c550a2e589910ce51bbc8352ff57c mem_calloc -> p_new --- diff --git a/alias.c b/alias.c index 8a6c892..f5b6859 100644 --- a/alias.c +++ b/alias.c @@ -256,7 +256,7 @@ retry_name: } } - new = mem_calloc (1, sizeof (ALIAS)); + new = p_new(ALIAS, 1); new->self = new; new->name = str_dup (buf); diff --git a/browser.c b/browser.c index ff4dc3d..5baa3b7 100644 --- a/browser.c +++ b/browser.c @@ -463,9 +463,7 @@ static void init_state (struct browser_state *state, MUTTMENU * menu) { 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 @@ -1005,7 +1003,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, 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]; @@ -1020,7 +1018,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, } 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; diff --git a/buffy.c b/buffy.c index ddb0ec7..7688aa4 100644 --- a/buffy.c +++ b/buffy.c @@ -222,7 +222,7 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, } 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); diff --git a/color.c b/color.c index ffc04db..854dde5 100644 --- a/color.c +++ b/color.c @@ -100,7 +100,7 @@ static struct mapping_t Fields[] = { 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; diff --git a/compose.c b/compose.c index 78f1ab9..8c0006a 100644 --- a/compose.c +++ b/compose.c @@ -755,7 +755,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ 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++); @@ -803,7 +803,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ 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) @@ -928,7 +928,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ 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++); @@ -1197,7 +1197,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ 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); diff --git a/compress.c b/compress.c index 622bbc5..47f50c5 100644 --- a/compress.c +++ b/compress.c @@ -478,7 +478,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) } 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; diff --git a/copy.c b/copy.c index d312d46..19b3d8c 100644 --- a/copy.c +++ b/copy.c @@ -128,7 +128,7 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, 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) { @@ -938,9 +938,7 @@ static int address_header_decode (char **h) 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); diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 25f8f02..0c0bbf7 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -212,11 +212,11 @@ static char crypt_flags (int flags) } /* 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; @@ -3037,7 +3037,7 @@ static char *list_to_pattern (LIST * list) 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) { @@ -3108,7 +3108,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, 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); @@ -3154,7 +3154,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, #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; @@ -3190,7 +3190,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, 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; diff --git a/enter.c b/enter.c index cda61f2..1b97bd4 100644 --- a/enter.c +++ b/enter.c @@ -151,7 +151,7 @@ static void replace_part (ENTER_STATE *state, size_t from, const char *buf) { /* 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)); @@ -638,7 +638,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, 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; diff --git a/gnupgparse.c b/gnupgparse.c index 080bc29..1166a91 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -144,7 +144,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) return NULL; if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB)))) - k = mem_calloc (sizeof *k, 1); + k = pgp_new_keyinfo(); break; } @@ -248,7 +248,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) 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; diff --git a/handler.c b/handler.c index a1a1353..39bc056 100644 --- a/handler.c +++ b/handler.c @@ -685,8 +685,8 @@ int text_enriched_handler (BODY * a, STATE * s) ((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; diff --git a/hash.c b/hash.c index 3cd6140..ac9dc1c 100644 --- a/hash.c +++ b/hash.c @@ -48,7 +48,7 @@ HASH *hash_create (int nelem) 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; } diff --git a/hcache.c b/hcache.c index e31aabc..e69a591 100644 --- a/hcache.c +++ b/hcache.c @@ -609,7 +609,7 @@ HEADER *mutt_hcache_restore (const unsigned char *d, HEADER ** oh) 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); @@ -731,7 +731,7 @@ mutt_hcache_delete(void *db, const char *filename, 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; diff --git a/history.c b/history.c index 2976633..304c7b9 100644 --- a/history.c +++ b/history.c @@ -41,7 +41,7 @@ static void init_history (struct history *h) } if (HistSize) - h->hist = mem_calloc (HistSize, sizeof (char *)); + h->hist = p_new(char *, HistSize); h->cur = 0; h->last = 0; diff --git a/hook.c b/hook.c index d665cb3..62fc7ff 100644 --- a/hook.c +++ b/hook.c @@ -186,11 +186,11 @@ int mutt_parse_hook (BUFFER * buf, BUFFER * s, unsigned long data, } 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; diff --git a/imap/imap.c b/imap/imap.c index 8c7cc5e..3f988e8 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -692,8 +692,8 @@ int imap_open_mailbox (CONTEXT * ctx) } 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"); @@ -816,8 +816,7 @@ int imap_make_msg_set (IMAP_DATA * idata, BUFFER * buf, int flag, int changed) 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; diff --git a/imap/message.c b/imap/message.c index dcfe4ca..4781a36 100644 --- a/imap/message.c +++ b/imap/message.c @@ -133,7 +133,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) 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; @@ -224,7 +224,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) /* 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 @@ -796,7 +796,7 @@ char *imap_set_flags (IMAP_DATA * idata, HEADER * h, char *s) 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) { diff --git a/imap/mx_imap.c b/imap/mx_imap.c index dbec056..53056fc 100644 --- a/imap/mx_imap.c +++ b/imap/mx_imap.c @@ -63,7 +63,7 @@ static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) { } 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; diff --git a/imap/util.c b/imap/util.c index 1025cea..8bb4dcf 100644 --- a/imap/util.c +++ b/imap/util.c @@ -191,7 +191,7 @@ void imap_error (const char *where, const char *msg) * 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. */ @@ -497,7 +497,7 @@ void imap_keepalive (void) 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); diff --git a/init.c b/init.c index cb580c5..ab1e583 100644 --- a/init.c +++ b/init.c @@ -436,7 +436,7 @@ static int rx_from_string (struct option_t* dst, const char* val, } 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; @@ -642,7 +642,7 @@ static void add_to_list (LIST ** list, const char *str) } 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; @@ -1431,7 +1431,7 @@ static int parse_alias (BUFFER * buf, BUFFER * s, unsigned long data, 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 */ @@ -1602,7 +1602,7 @@ static void mutt_set_default(const char *name, void* p, unsigned long more) 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)); diff --git a/keymap.c b/keymap.c index d28ca0f..a879852 100644 --- a/keymap.c +++ b/keymap.c @@ -99,7 +99,7 @@ static struct keymap_t *allocKeys(int len, keycode_t *keys) { 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; diff --git a/lib/list.c b/lib/list.c index 207e336..efa4c98 100644 --- a/lib/list.c +++ b/lib/list.c @@ -18,7 +18,7 @@ #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) { diff --git a/lib/mem.c b/lib/mem.c index ab23acc..df2e2ed 100644 --- a/lib/mem.c +++ b/lib/mem.c @@ -10,25 +10,6 @@ #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; diff --git a/lib/mem.h b/lib/mem.h index e46f34d..ac8f811 100644 --- a/lib/mem.h +++ b/lib/mem.h @@ -8,10 +8,7 @@ #include -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 */ diff --git a/lib/rx.c b/lib/rx.c index 772fa8d..616d824 100644 --- a/lib/rx.c +++ b/lib/rx.c @@ -16,10 +16,10 @@ #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); diff --git a/list.h b/list.h index 89916ff..11a88b4 100644 --- a/list.h +++ b/list.h @@ -14,7 +14,7 @@ typedef struct list_t { 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 *); diff --git a/mbox.c b/mbox.c index 030b55b..7a5d875 100644 --- a/mbox.c +++ b/mbox.c @@ -646,8 +646,8 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) 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++) { /* @@ -1140,7 +1140,7 @@ static int mmdf_commit_message (MESSAGE* msg, CONTEXT* ctx) { } 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; diff --git a/menu.c b/menu.c index d8f2baf..51c0b1a 100644 --- a/menu.c +++ b/menu.c @@ -644,7 +644,7 @@ static int menu_search_generic (MUTTMENU * m, regex_t * re, int n) 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; diff --git a/mh.c b/mh.c index 90cf30a..ee799b3 100644 --- a/mh.c +++ b/mh.c @@ -646,7 +646,7 @@ static int maildir_parse_entry (CONTEXT * ctx, struct maildir ***last, 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 @@ -1978,7 +1978,7 @@ static int maildir_is_magic (const char* path, struct stat* st) { /* 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; diff --git a/mutt.h b/mutt.h index 6d834c5..c3a3801 100644 --- a/mutt.h +++ b/mutt.h @@ -541,7 +541,7 @@ typedef struct spam_list_t { } 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 *); diff --git a/mutt_idna.c b/mutt_idna.c index 1ad3b62..0918f7c 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -131,8 +131,7 @@ static int mbox_to_udomain (const char *mbx, char **user, char **domain) 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; } diff --git a/mutt_socket.c b/mutt_socket.c index 90a8dde..1c3d865 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -326,7 +326,7 @@ static CONNECTION *socket_new_conn (void) { CONNECTION *conn; - conn = (CONNECTION *) mem_calloc (1, sizeof (CONNECTION)); + conn = p_new(CONNECTION, 1); conn->fd = -1; return conn; diff --git a/mutt_ssl.c b/mutt_ssl.c index 801da78..6a83032 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -88,7 +88,7 @@ int mutt_ssl_starttls (CONNECTION * 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")); @@ -260,7 +260,7 @@ static int ssl_socket_open (CONNECTION * conn) 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 ()); @@ -586,9 +586,9 @@ static int ssl_check_certificate (sslsockdata * data) /* 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:"), diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index a6e2cf4..91b03dd 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -159,7 +159,7 @@ static int tls_negotiate (CONNECTION * conn) 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) { @@ -308,7 +308,7 @@ static int tls_compare_certificates (const gnutls_datum * peercert) 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; @@ -587,9 +587,9 @@ static int tls_check_certificate (CONNECTION * conn) /* 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:"), diff --git a/muttlib.c b/muttlib.c index fd1cea5..0e4027a 100644 --- a/muttlib.c +++ b/muttlib.c @@ -55,7 +55,7 @@ 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; diff --git a/mx.c b/mx.c index e173aad..c68b0ac 100644 --- a/mx.c +++ b/mx.c @@ -1130,7 +1130,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) return (NULL); } - msg = mem_calloc (1, sizeof (MESSAGE)); + msg = p_new(MESSAGE, 1); msg->magic = dest->magic; msg->write = 1; @@ -1192,7 +1192,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) { MESSAGE *msg; - msg = mem_calloc (1, sizeof (MESSAGE)); + msg = p_new(MESSAGE, 1); switch (msg->magic = ctx->magic) { case M_MBOX: case M_MMDF: @@ -1314,8 +1314,8 @@ void mx_alloc_memory (CONTEXT * ctx) 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; diff --git a/nntp/mx_nntp.c b/nntp/mx_nntp.c index 3d7196b..bc1d77d 100644 --- a/nntp/mx_nntp.c +++ b/nntp/mx_nntp.c @@ -42,7 +42,7 @@ static int acl_check_nntp (CONTEXT* ctx, int bit) { /* 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; diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 3f707ab..b711b2f 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -44,7 +44,7 @@ void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d) if (!s || !d) return; - l = mem_calloc (1, sizeof (LIST)); + l = p_new(LIST, 1); if (s->list) s->tail->next = l; else @@ -76,8 +76,7 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) 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; @@ -92,7 +91,7 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) 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 == ':') @@ -229,9 +228,7 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) } 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; @@ -348,7 +345,7 @@ NNTP_SERVER *mutt_select_newsserver (char *server) 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'); @@ -398,7 +395,7 @@ NNTP_SERVER *mutt_select_newsserver (char *server) } /* 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); @@ -577,7 +574,7 @@ void newsrc_gen_entries (CONTEXT * ctx) } if (!data->max) { - data->entries = mem_calloc (5, sizeof (NEWSRC_ENTRY)); + data->entries = p_new(NEWSRC_ENTRY, 5); data->max = 5; } @@ -756,7 +753,7 @@ int mutt_newsrc_update (NNTP_SERVER * news) 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; @@ -996,8 +993,7 @@ NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group) 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; @@ -1038,7 +1034,7 @@ NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group) !(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; @@ -1062,7 +1058,7 @@ NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group) !(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; diff --git a/nntp/nntp.c b/nntp/nntp.c index 84e106f..9674316 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -713,7 +713,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first, 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); @@ -866,7 +866,7 @@ int nntp_open_mailbox (CONTEXT * ctx) /* 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); @@ -1236,7 +1236,7 @@ static int _nntp_check_mailbox (CONTEXT * ctx, NNTP_DATA * nntp_data) /* 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; @@ -1277,7 +1277,7 @@ static int add_group (char *buf, void *serv) 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; diff --git a/pager.c b/pager.c index c3800df..31f139a 100644 --- a/pager.c +++ b/pager.c @@ -377,7 +377,7 @@ static struct q_class_t *classify_quote (struct q_class_t **QuoteList, /* 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; } @@ -398,10 +398,8 @@ static struct q_class_t *classify_quote (struct q_class_t **QuoteList, /* 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 */ @@ -501,11 +499,8 @@ static struct q_class_t *classify_quote (struct q_class_t **QuoteList, /* 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 */ @@ -598,10 +593,8 @@ static struct q_class_t *classify_quote (struct q_class_t **QuoteList, /* 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) { @@ -632,9 +625,8 @@ static struct q_class_t *classify_quote (struct q_class_t **QuoteList, 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); diff --git a/pgplib.c b/pgplib.c index 364f1a9..f0ffda8 100644 --- a/pgplib.c +++ b/pgplib.c @@ -146,7 +146,7 @@ pgp_uid_t *pgp_copy_uids (pgp_uid_t * up, pgp_key_t parent) 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); diff --git a/pgplib.h b/pgplib.h index e6f7c1f..e63ba74 100644 --- a/pgplib.h +++ b/pgplib.h @@ -71,6 +71,6 @@ short pgp_get_abilities (unsigned char); 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 */ diff --git a/pgppubring.c b/pgppubring.c index 9f2ee46..20b4b92 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -638,7 +638,7 @@ static pgp_key_t pgp_parse_keyblock (FILE * fp) 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; @@ -671,7 +671,7 @@ static pgp_key_t pgp_parse_keyblock (FILE * fp) 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; diff --git a/pop/mx_pop.c b/pop/mx_pop.c index 822471e..34b6b45 100644 --- a/pop/mx_pop.c +++ b/pop/mx_pop.c @@ -41,7 +41,7 @@ static int acl_check_pop (CONTEXT* ctx, int bit) { } 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; diff --git a/pop/pop.c b/pop/pop.c index b8e9e06..1b70009 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -251,7 +251,7 @@ int pop_open_mailbox (CONTEXT * ctx) 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; @@ -526,7 +526,7 @@ void pop_fetch_mail (void) 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'); @@ -544,7 +544,7 @@ void pop_fetch_mail (void) 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) { diff --git a/protos.h b/protos.h index 07506ff..c650c62 100644 --- a/protos.h +++ b/protos.h @@ -28,10 +28,10 @@ void _mutt_make_string (char *, size_t, const char *, CONTEXT *, #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 *, @@ -313,7 +313,7 @@ int mutt_wctoutf8 (char *s, unsigned int c); (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); diff --git a/query.c b/query.c index 893d2db..ba3a5a4 100644 --- a/query.c +++ b/query.c @@ -102,11 +102,11 @@ static QUERY *run_query (char *s, int quiet) 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; } @@ -289,8 +289,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) 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; @@ -346,8 +345,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) 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++) diff --git a/recvattach.c b/recvattach.c index a592e15..e71d85b 100644 --- a/recvattach.c +++ b/recvattach.c @@ -146,7 +146,7 @@ ATTACHPTR **mutt_gen_attach_list (BODY * m, } else { if (!idx[*idxlen]) - idx[*idxlen] = (ATTACHPTR *) mem_calloc (1, sizeof (ATTACHPTR)); + idx[*idxlen] = p_new(ATTACHPTR, 1); new = idx[(*idxlen)++]; new->content = m; diff --git a/remailer.c b/remailer.c index 08dc174..6181c73 100644 --- a/remailer.c +++ b/remailer.c @@ -115,7 +115,7 @@ static void mix_add_entry (REMAILER *** type2_list, REMAILER * entry, static REMAILER *mix_new_remailer (void) { - return mem_calloc (1, sizeof (REMAILER)); + return p_new(REMAILER, 1); } static void mix_free_remailer (REMAILER ** r) @@ -496,7 +496,7 @@ void mix_make_chain (LIST ** chainp, int *redraw) *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); diff --git a/rfc1524.c b/rfc1524.c index c0397ad..026050f 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -321,7 +321,7 @@ static int rfc1524_mailcap_parse (BODY * a, 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) diff --git a/rfc2231.c b/rfc2231.c index 04f9515..29d60df 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -167,7 +167,7 @@ void rfc2231_decode_parameters (PARAMETER ** headp) 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) diff --git a/score.c b/score.c index 071b0fa..7fe90f6 100644 --- a/score.c +++ b/score.c @@ -88,7 +88,7 @@ int mutt_parse_score (BUFFER * buf, BUFFER * s, unsigned long data, p_delete(&pattern); return (-1); } - ptr = mem_calloc (1, sizeof (SCORE)); + ptr = p_new(SCORE, 1); if (last) last->next = ptr; else diff --git a/sendlib.c b/sendlib.c index 0dca3d5..e1c8a3d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -618,10 +618,10 @@ static size_t convert_file_to (FILE * file, const char *fromcode, 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")) @@ -833,7 +833,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) 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)) { diff --git a/smime.c b/smime.c index 95083df..728d111 100644 --- a/smime.c +++ b/smime.c @@ -391,7 +391,7 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public) } /* 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), @@ -856,14 +856,13 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, 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++; } } diff --git a/thread.c b/thread.c index 57b1bcb..f64dc3f 100644 --- a/thread.c +++ b/thread.c @@ -346,7 +346,7 @@ static LIST *make_subject_list (THREAD * cur, time_t * dateptr) 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; @@ -549,7 +549,7 @@ THREAD *mutt_sort_subthreads (THREAD * thread, int init) 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; @@ -758,7 +758,7 @@ void mutt_sort_threads (CONTEXT * ctx, int init) 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; @@ -839,7 +839,7 @@ void mutt_sort_threads (CONTEXT * ctx, int init) 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 {