menu->max++;
}
- safe_realloc(&AliasTable, menu->max * sizeof(struct Alias *));
+ mutt_mem_realloc(&AliasTable, menu->max * sizeof(struct Alias *));
menu->data = AliasTable;
if (!AliasTable)
return;
}
}
- new = safe_calloc(1, sizeof(struct Alias));
+ new = mutt_mem_calloc(1, sizeof(struct Alias));
new->name = safe_strdup(buf);
mutt_addrlist_to_local(adr);
if (a->name && (strstr(a->name, s) == a->name))
{
if (!a_list) /* init */
- a_cur = a_list = safe_malloc(sizeof(struct Alias));
+ a_cur = a_list = mutt_mem_malloc(sizeof(struct Alias));
else
{
- a_cur->next = safe_malloc(sizeof(struct Alias));
+ a_cur->next = mutt_mem_malloc(sizeof(struct Alias));
a_cur = a_cur->next;
}
memcpy(a_cur, a, sizeof(struct Alias));
if (actx->idxlen == actx->idxmax)
{
actx->idxmax += 5;
- safe_realloc(&actx->idx, sizeof(struct AttachPtr *) * actx->idxmax);
- safe_realloc(&actx->v2r, sizeof(short) * actx->idxmax);
+ mutt_mem_realloc(&actx->idx, sizeof(struct AttachPtr *) * actx->idxmax);
+ mutt_mem_realloc(&actx->v2r, sizeof(short) * actx->idxmax);
for (i = actx->idxlen; i < actx->idxmax; i++)
actx->idx[i] = NULL;
}
if (actx->fp_len == actx->fp_max)
{
actx->fp_max += 5;
- safe_realloc(&actx->fp_idx, sizeof(FILE *) * actx->fp_max);
+ mutt_mem_realloc(&actx->fp_idx, sizeof(FILE *) * actx->fp_max);
for (i = actx->fp_len; i < actx->fp_max; i++)
actx->fp_idx[i] = NULL;
}
if (actx->body_len == actx->body_max)
{
actx->body_max += 5;
- safe_realloc(&actx->body_idx, sizeof(struct Body *) * actx->body_max);
+ mutt_mem_realloc(&actx->body_idx, sizeof(struct Body *) * actx->body_max);
for (i = actx->body_len; i < actx->body_max; i++)
actx->body_idx[i] = NULL;
}
if (!account)
goto bail;
- bcache = safe_calloc(1, sizeof(struct BodyCache));
+ bcache = mutt_mem_calloc(1, sizeof(struct BodyCache));
if (bcache_path(account, mailbox, bcache->path, sizeof(bcache->path)) < 0)
goto bail;
bcache->pathlen = mutt_strlen(bcache->path);
struct Body *mutt_new_body(void)
{
- struct Body *p = safe_calloc(1, sizeof(struct Body));
+ struct Body *p = mutt_mem_calloc(1, sizeof(struct Body));
p->disposition = DISPATTACH;
p->use_disp = true;
if (state->entrylen == state->entrymax)
{
/* need to allocate more space */
- safe_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256));
+ mutt_mem_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256));
memset(&state->entry[state->entrylen], 0, sizeof(struct FolderFile) * 256);
if (m)
m->data = state->entry;
{
state->entrylen = 0;
state->entrymax = 256;
- state->entry = safe_calloc(state->entrymax, sizeof(struct FolderFile));
+ state->entry = mutt_mem_calloc(state->entrymax, sizeof(struct FolderFile));
#ifdef USE_IMAP
state->imap_browse = false;
#endif
if (menu->tagged)
{
*numfiles = menu->tagged;
- tfiles = safe_calloc(*numfiles, sizeof(char *));
+ tfiles = mutt_mem_calloc(*numfiles, sizeof(char *));
for (int j = 0, k = 0; j < state.entrylen; j++)
{
struct FolderFile ff = state.entry[j];
else if (f[0]) /* no tagged entries. return selected entry */
{
*numfiles = 1;
- tfiles = safe_calloc(*numfiles, sizeof(char *));
+ tfiles = mutt_mem_calloc(*numfiles, sizeof(char *));
mutt_expand_path(f, flen);
tfiles[0] = safe_strdup(f);
*files = tfiles;
strfcpy(buf, NONULL(Mask.pattern), sizeof(buf));
if (mutt_get_field(_("File Mask: "), buf, sizeof(buf), 0) == 0)
{
- regex_t *rx = safe_malloc(sizeof(regex_t));
+ regex_t *rx = mutt_mem_malloc(sizeof(regex_t));
char *s = buf;
int not = 0, err;
char rp[PATH_MAX] = "";
char *r = NULL;
- buffy = safe_calloc(1, sizeof(struct Buffy));
+ buffy = mutt_mem_calloc(1, sizeof(struct Buffy));
strfcpy(buffy->path, path, sizeof(buffy->path));
r = realpath(path, rp);
strfcpy(buffy->realpath, r ? rp : path, sizeof(buffy->realpath));
ib = s;
ibl = len + 1;
obl = MB_LEN_MAX * ibl;
- ob = buf = safe_malloc(obl + 1);
+ ob = buf = mutt_mem_malloc(obl + 1);
mutt_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl);
iconv_close(cd);
if (cd != (iconv_t) -1)
{
- fc = safe_malloc(sizeof(struct FgetConv));
+ fc = mutt_mem_malloc(sizeof(struct FgetConv));
fc->p = fc->ob = fc->bufo;
fc->ib = fc->bufi;
fc->ibl = 0;
fc->inrepls = mutt_is_utf8(to) ? repls : repls + 1;
}
else
- fc = safe_malloc(sizeof(struct FgetConvNot));
+ fc = mutt_mem_malloc(sizeof(struct FgetConvNot));
fc->file = file;
fc->cd = cd;
return (FGETCONV *) fc;
static struct ColorLine *new_color_line(void)
{
- struct ColorLine *p = safe_calloc(1, sizeof(struct ColorLine));
+ struct ColorLine *p = mutt_mem_calloc(1, sizeof(struct ColorLine));
p->fg = p->bg = -1;
void ci_start_color(void)
{
memset(ColorDefs, A_NORMAL, sizeof(int) * MT_COLOR_MAX);
- ColorQuote = safe_malloc(COLOR_QUOTE_INIT * sizeof(int));
+ ColorQuote = mutt_mem_malloc(COLOR_QUOTE_INIT * sizeof(int));
memset(ColorQuote, A_NORMAL, sizeof(int) * COLOR_QUOTE_INIT);
ColorQuoteSize = COLOR_QUOTE_INIT;
ColorQuoteUsed = 0;
i++;
}
- p = safe_malloc(sizeof(struct ColorList));
+ p = mutt_mem_malloc(sizeof(struct ColorList));
p->next = ColorList;
ColorList = p;
{
if (q_level >= ColorQuoteSize)
{
- safe_realloc(&ColorQuote, (ColorQuoteSize += 2) * sizeof(int));
+ mutt_mem_realloc(&ColorQuote, (ColorQuoteSize += 2) * sizeof(int));
ColorQuote[ColorQuoteSize - 2] = ColorDefs[MT_COLOR_QUOTED];
ColorQuote[ColorQuoteSize - 1] = ColorDefs[MT_COLOR_QUOTED];
}
return;
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
mutt_buffer_init(&token);
r = mutt_parse_rc_line(buffer, &token, &err);
FREE(&token.data);
}
else
{
- new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr));
mutt_actx_add_attach(actx, new);
new->content = m;
m->aptr = new;
menu->redraw_data = &rd;
mutt_push_current_menu(menu);
- actx = safe_calloc(sizeof(struct AttachCtx), 1);
+ actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1);
actx->hdr = msg;
mutt_update_compose_menu(actx, menu, 1);
case OP_COMPOSE_ATTACH_KEY:
if (!(WithCrypto & APPLICATION_PGP))
break;
- new = safe_calloc(1, sizeof(struct AttachPtr));
+ new = mutt_mem_calloc(1, sizeof(struct AttachPtr));
new->content = crypt_pgp_make_key_attachment(NULL);
if (new->content)
{
for (i = 0; i < numfiles; i++)
{
char *att = files[i];
- new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr));
new->unowned = 1;
new->content = mutt_make_file_attach(att);
if (new->content)
if (!message_is_tagged(Context, i))
continue;
- new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr));
new->content = mutt_make_message_attach(Context, Context->hdrs[i], 1);
if (new->content != NULL)
update_idx(menu, actx, new);
mutt_error(_("Unknown Content-Type %s"), type);
continue;
}
- new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr));
/* Touch the file */
fp = mutt_file_fopen(fname, "w");
if (!fp)
const char *c = find_hook(MUTT_CLOSEHOOK, ctx->path);
const char *a = find_hook(MUTT_APPENDHOOK, ctx->path);
- struct CompressInfo *ci = safe_calloc(1, sizeof(struct CompressInfo));
+ struct CompressInfo *ci = mutt_mem_calloc(1, sizeof(struct CompressInfo));
ctx->compress_info = ci;
ci->open = safe_strdup(o);
int status;
struct timespec timeout = { 0, 100000000 };
struct gaicb *reqs[1];
- reqs[0] = safe_calloc(1, sizeof(*reqs[0]));
+ reqs[0] = mutt_mem_calloc(1, sizeof(*reqs[0]));
reqs[0]->ar_name = node;
reqs[0]->ar_request = &hints;
if (getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0)
len = strlen(account->pass);
- safe_realloc(&secret_ptr, sizeof(sasl_secret_t) + len);
+ mutt_mem_realloc(&secret_ptr, sizeof(sasl_secret_t) + len);
memcpy((char *) secret_ptr->data, account->pass, (size_t) len);
secret_ptr->len = len;
*psecret = secret_ptr;
return SASL_FAIL;
interaction->len = mutt_strlen(resp) + 1;
- interaction->result = safe_malloc(interaction->len);
+ interaction->result = mutt_mem_malloc(interaction->len);
memcpy((char *) interaction->result, resp, interaction->len);
interaction++;
*/
void mutt_sasl_setup_conn(struct Connection *conn, sasl_conn_t *saslconn)
{
- struct SaslData *sasldata = safe_malloc(sizeof(struct SaslData));
+ struct SaslData *sasldata = mutt_mem_malloc(sizeof(struct SaslData));
/* work around sasl_getprop aliasing issues */
const void *tmp = NULL;
{
struct Connection *conn = NULL;
- conn = safe_calloc(1, sizeof(struct Connection));
+ conn = mutt_mem_calloc(1, sizeof(struct Connection));
conn->fd = -1;
return conn;
buflen = BIO_get_mem_data(bio, &buf);
if (buflen > 0)
{
- output = safe_malloc(buflen + 1);
+ output = mutt_mem_malloc(buflen + 1);
memcpy(output, buf, buflen);
output[buflen] = '\0';
mutt_debug(1, "SSL error stack: %s\n", output);
goto out;
}
bufsize++; /* space for the terminal nul char */
- buf = safe_malloc((size_t) bufsize);
+ buf = mutt_mem_malloc((size_t) bufsize);
if (X509_NAME_get_text_by_NID(x509_subject, NID_commonName, buf, bufsize) == -1)
{
if (err && errlen)
mutt_push_current_menu(menu);
menu->max = mutt_array_size(part) * 2 + 10;
- menu->dialog = safe_calloc(1, menu->max * sizeof(char *));
+ menu->dialog = mutt_mem_calloc(1, menu->max * sizeof(char *));
for (int i = 0; i < menu->max; i++)
- menu->dialog[i] = safe_calloc(1, SHORT_STRING * sizeof(char));
+ menu->dialog[i] = mutt_mem_calloc(1, SHORT_STRING * sizeof(char));
row = 0;
strfcpy(menu->dialog[row], _("This certificate belongs to:"), SHORT_STRING);
if (raw_socket_open(conn) < 0)
return -1;
- data = safe_calloc(1, sizeof(struct SslSockData));
+ data = mutt_mem_calloc(1, sizeof(struct SslSockData));
conn->sockdata = data;
data->ctx = SSL_CTX_new(SSLv23_client_method());
if (ssl_init())
goto bail;
- ssldata = safe_calloc(1, sizeof(struct SslSockData));
+ ssldata = mutt_mem_calloc(1, sizeof(struct SslSockData));
/* the ssl_use_xxx protocol options don't apply. We must use TLS in TLS.
*
* However, we need to be able to negotiate amongst various TLS versions,
return 0;
b64_data.size = filestat.st_size + 1;
- b64_data_data = safe_calloc(1, b64_data.size);
+ b64_data_data = mutt_mem_calloc(1, b64_data.size);
b64_data_data[b64_data.size - 1] = '\0';
b64_data.data = b64_data_data;
menu = mutt_new_menu(MENU_GENERIC);
menu->max = 25;
- menu->dialog = safe_calloc(1, menu->max * sizeof(char *));
+ menu->dialog = mutt_mem_calloc(1, menu->max * sizeof(char *));
for (int i = 0; i < menu->max; i++)
- menu->dialog[i] = safe_calloc(1, SHORT_STRING * sizeof(char));
+ menu->dialog[i] = mutt_mem_calloc(1, SHORT_STRING * sizeof(char));
mutt_push_current_menu(menu);
row = 0;
int err;
priority_size = SHORT_STRING + mutt_strlen(SslCiphers);
- priority = safe_malloc(priority_size);
+ priority = mutt_mem_malloc(priority_size);
priority[0] = 0;
if (SslCiphers)
struct TlsSockData *data = NULL;
int err;
- data = safe_calloc(1, sizeof(struct TlsSockData));
+ data = mutt_mem_calloc(1, sizeof(struct TlsSockData));
conn->sockdata = data;
err = gnutls_certificate_allocate_credentials(&data->xcred);
if (err < 0)
int pin[2], pout[2];
int devnull;
- tunnel = safe_malloc(sizeof(struct TunnelData));
+ tunnel = mutt_mem_malloc(sizeof(struct TunnelData));
conn->sockdata = tunnel;
mutt_message(_("Connecting with \"%s\"..."), Tunnel);
mutt_debug(1, "WEED is %s\n", (flags & CH_WEED) ? "Set" : "Not");
- headers = safe_calloc(hdr_count, sizeof(char *));
+ headers = mutt_mem_calloc(hdr_count, sizeof(char *));
/* Read all the headers into the array */
while (ftello(in) < off_end)
{
int hlen = mutt_strlen(headers[x]);
- safe_realloc(&headers[x], hlen + this_one_len + sizeof(char));
+ mutt_mem_realloc(&headers[x], hlen + this_one_len + sizeof(char));
strcat(headers[x] + hlen, this_one);
FREE(&this_one);
}
{
int blen = mutt_strlen(buf);
- safe_realloc(&this_one, this_one_len + blen + sizeof(char));
+ mutt_mem_realloc(&this_one, this_one_len + blen + sizeof(char));
strcat(this_one + this_one_len, buf);
this_one_len += blen;
}
{
int hlen = mutt_strlen(headers[x]);
- safe_realloc(&headers[x], hlen + this_one_len + sizeof(char));
+ mutt_mem_realloc(&headers[x], hlen + this_one_len + sizeof(char));
strcat(headers[x] + hlen, this_one);
FREE(&this_one);
}
plen = linelen;
buflen = linelen + 3;
- safe_realloc(h, buflen);
+ mutt_mem_realloc(h, buflen);
for (int count = 0; a; a = a->next, count++)
{
struct Address *tmp = a->next;
cbuflen = mutt_strlen(cbuf);
c2buflen = mutt_strlen(c2buf);
buflen += l + cbuflen + c2buflen;
- safe_realloc(h, buflen);
+ mutt_mem_realloc(h, buflen);
p = *h;
strcat(p + plen, cbuf);
plen += cbuflen;
*h = safe_strdup(s);
else
{
- *h = safe_calloc(1, l + 2);
+ *h = mutt_mem_calloc(1, l + 2);
strfcpy(*h, s, l + 1);
format_address_header(h, a);
}
void mutt_init_windows(void)
{
- MuttHelpWindow = safe_calloc(1, sizeof(struct MuttWindow));
- MuttIndexWindow = safe_calloc(1, sizeof(struct MuttWindow));
- MuttStatusWindow = safe_calloc(1, sizeof(struct MuttWindow));
- MuttMessageWindow = safe_calloc(1, sizeof(struct MuttWindow));
+ MuttHelpWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+ MuttIndexWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+ MuttStatusWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+ MuttMessageWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
#ifdef USE_SIDEBAR
- MuttSidebarWindow = safe_calloc(1, sizeof(struct MuttWindow));
+ MuttSidebarWindow = mutt_mem_calloc(1, sizeof(struct MuttWindow));
#endif
}
}
else
{
- char *pc = safe_malloc(mutt_strlen(prompt) + 3);
+ char *pc = mutt_mem_malloc(mutt_strlen(prompt) + 3);
sprintf(pc, "%s: ", prompt);
mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
tmp.op = op;
if (UngetCount >= UngetLen)
- safe_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event));
+ mutt_mem_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event));
UngetKeyEvents[UngetCount++] = tmp;
}
tmp.op = op;
if (MacroBufferCount >= MacroBufferLen)
- safe_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event));
+ mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event));
MacroEvents[MacroBufferCount++] = tmp;
}
if (option(OPT_UNCOLLAPSE_NEW) && oldcount && check != MUTT_REOPENED &&
((Sort & SORT_MASK) == SORT_THREADS))
{
- save_new = safe_malloc(sizeof(struct Header *) * (ctx->msgcount - oldcount));
+ save_new = mutt_mem_malloc(sizeof(struct Header *) * (ctx->msgcount - oldcount));
for (int i = oldcount; i < ctx->msgcount; i++)
save_new[i - oldcount] = ctx->hdrs[i];
}
if (!found)
{
chunks++;
- safe_realloc(&syntax, chunks * sizeof(struct Syntax));
+ mutt_mem_realloc(&syntax, chunks * sizeof(struct Syntax));
}
i = chunks - 1;
break;
bytes -= mutt_strlen(p);
if (*bufmax == *buflen)
- safe_realloc(&buf, sizeof(char *) * (*bufmax += 25));
+ mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25));
buf[(*buflen)++] = safe_strdup(tmp);
}
if (buf && *bufmax == *buflen)
{ /* Do not smash memory past buf */
- safe_realloc(&buf, sizeof(char *) * (++*bufmax));
+ mutt_mem_realloc(&buf, sizeof(char *) * (++*bufmax));
}
if (buf)
buf[*buflen] = NULL;
}
if (*bufmax == *buflen)
- safe_realloc(&buf, sizeof(char *) * (*bufmax += 25));
+ mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25));
buf[(*buflen)++] = safe_strdup(tmp);
bytes = Context->hdrs[n]->content->length;
buf = be_snarf_data(Context->fp, buf, bufmax, buflen, offset, bytes, pfx);
if (*bufmax == *buflen)
- safe_realloc(&buf, sizeof(char *) * (*bufmax += 25));
+ mutt_mem_realloc(&buf, sizeof(char *) * (*bufmax += 25));
buf[(*buflen)++] = safe_strdup("\n");
}
else
{
safe_strcat(tmp, sizeof(tmp), "\n");
if (buflen == bufmax)
- safe_realloc(&buf, sizeof(char *) * (bufmax += 25));
+ mutt_mem_realloc(&buf, sizeof(char *) * (bufmax += 25));
buf[buflen++] = safe_strdup(tmp[1] == '~' ? tmp + 1 : tmp);
}
if (savelen)
{
- savebuf = safe_calloc(savelen, sizeof(wchar_t));
+ savebuf = mutt_mem_calloc(savelen, sizeof(wchar_t));
memcpy(savebuf, state->wbuf + state->curpos, savelen * sizeof(wchar_t));
}
if (state->curpos + savelen > state->wbuflen)
{
state->wbuflen = state->curpos + savelen;
- safe_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t));
+ mutt_mem_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t));
}
/* Restore suffix */
if (!mutt_complete(buf, buflen))
{
templen = state->lastchar - i;
- safe_realloc(&tempbuf, templen * sizeof(wchar_t));
+ mutt_mem_realloc(&tempbuf, templen * sizeof(wchar_t));
}
else
BEEP();
if (!mutt_complete(buf, buflen))
{
templen = state->lastchar;
- safe_realloc(&tempbuf, templen * sizeof(wchar_t));
+ mutt_mem_realloc(&tempbuf, templen * sizeof(wchar_t));
memcpy(tempbuf, state->wbuf, templen * sizeof(wchar_t));
}
else
{
char **tfiles = NULL;
*numfiles = 1;
- tfiles = safe_calloc(*numfiles, sizeof(char *));
+ tfiles = mutt_mem_calloc(*numfiles, sizeof(char *));
mutt_expand_path(buf, buflen);
tfiles[0] = safe_strdup(buf);
*files = tfiles;
if (state->lastchar >= state->wbuflen)
{
state->wbuflen = state->lastchar + 20;
- safe_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t));
+ mutt_mem_realloc(&state->wbuf, state->wbuflen * sizeof(wchar_t));
}
memmove(state->wbuf + state->curpos + 1, state->wbuf + state->curpos,
(state->lastchar - state->curpos) * sizeof(wchar_t));
static inline struct EnterState *mutt_new_enter_state(void)
{
- return safe_calloc(1, sizeof(struct EnterState));
+ return mutt_mem_calloc(1, sizeof(struct EnterState));
}
#endif /* _MUTT_ENTER_STATE_H */
*/
struct Envelope *mutt_new_envelope(void)
{
- struct Envelope *e = safe_calloc(1, sizeof(struct Envelope));
+ struct Envelope *e = mutt_mem_calloc(1, sizeof(struct Envelope));
STAILQ_INIT(&e->references);
STAILQ_INIT(&e->in_reply_to);
STAILQ_INIT(&e->userhdrs);
if (!p)
{
mutt_debug(2, "mutt_pattern_group: Creating group %s.\n", k);
- p = safe_calloc(1, sizeof(struct Group));
+ p = mutt_mem_calloc(1, sizeof(struct Group));
p->name = safe_strdup(k);
mutt_hash_insert(Groups, p->name, p);
}
return;
}
- *ctx = safe_calloc(1, sizeof(struct GroupContext));
+ *ctx = mutt_mem_calloc(1, sizeof(struct GroupContext));
(*ctx)->g = group;
}
if (stte->line_used > stte->line_max)
{
stte->line_max = stte->line_used;
- safe_realloc(&stte->line, (stte->line_max + 1) * sizeof(wchar_t));
+ mutt_mem_realloc(&stte->line, (stte->line_max + 1) * sizeof(wchar_t));
}
wcscat(stte->line, stte->buffer);
stte->line_len += stte->word_len;
if (stte->tag_level[RICH_COLOR])
{
if (stte->param_used + 1 >= stte->param_len)
- safe_realloc(&stte->param, (stte->param_len += STRING) * sizeof(wchar_t));
+ mutt_mem_realloc(&stte->param, (stte->param_len += STRING) * sizeof(wchar_t));
stte->param[stte->param_used++] = c;
}
if (stte->buff_len < stte->buff_used + 3)
{
stte->buff_len += LONG_STRING;
- safe_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t));
+ mutt_mem_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t));
}
if ((!stte->tag_level[RICH_NOFILL] && iswspace(c)) || c == (wchar_t) '\0')
if (stte->buff_len < stte->buff_used + mutt_strlen(s))
{
stte->buff_len += LONG_STRING;
- safe_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t));
+ mutt_mem_realloc(&stte->buffer, (stte->buff_len + 1) * sizeof(wchar_t));
}
c = s;
while (*c)
(MuttIndexWindow->cols - 4) :
((MuttIndexWindow->cols - 4) < 72) ? (MuttIndexWindow->cols - 4) : 72);
stte.line_max = stte.wrap_margin * 4;
- stte.line = safe_calloc(1, (stte.line_max + 1) * sizeof(wchar_t));
- stte.param = safe_calloc(1, (STRING) * sizeof(wchar_t));
+ stte.line = mutt_mem_calloc(1, (stte.line_max + 1) * sizeof(wchar_t));
+ stte.param = mutt_mem_calloc(1, (STRING) * sizeof(wchar_t));
stte.param_len = STRING;
stte.param_used = 0;
u_int32_t createflags = DB_CREATE;
int pagesize;
- struct HcacheDbCtx *ctx = safe_malloc(sizeof(struct HcacheDbCtx));
+ struct HcacheDbCtx *ctx = mutt_mem_malloc(sizeof(struct HcacheDbCtx));
if (mutt_atoi(HeaderCachePageSize, &pagesize) < 0 || pagesize <= 0)
pagesize = 16384;
if (siz < 4096)
siz = 4096;
- return safe_malloc(siz);
+ return mutt_mem_malloc(siz);
}
static void lazy_realloc(void *ptr, size_t siz)
if (p != NULL && siz < 4096)
return;
- safe_realloc(ptr, siz);
+ mutt_mem_realloc(ptr, siz);
}
static unsigned char *dump_int(unsigned int i, unsigned char *d, int *off)
return;
}
- *c = safe_malloc(size);
+ *c = mutt_mem_malloc(size);
memcpy(*c, d + *off, size);
if (convert && !is_ascii(*c, size))
{
return;
}
- *b = safe_malloc(sizeof(struct Buffer));
+ *b = mutt_mem_malloc(sizeof(struct Buffer));
restore_char(&(*b)->data, d, off, convert);
restore_int(&offset, d, off);
while (counter)
{
- *p = safe_malloc(sizeof(struct Parameter));
+ *p = mutt_mem_malloc(sizeof(struct Parameter));
restore_char(&(*p)->attribute, d, off, false);
restore_char(&(*p)->value, d, off, convert);
p = &(*p)->next;
/* if the folder is local, canonify the path to avoid
* to ensure equivalent paths share the hcache */
- p = safe_malloc(PATH_MAX + 1);
+ p = mutt_mem_malloc(PATH_MAX + 1);
if (!realpath(path, p))
mutt_str_replace(&p, path);
if (!ops)
return NULL;
- header_cache_t *h = safe_calloc(1, sizeof(header_cache_t));
+ header_cache_t *h = mutt_mem_calloc(1, sizeof(header_cache_t));
/* Calculate the current hcache version from dynamic configuration */
if (hcachever == 0x0)
{
int rc;
- struct HcacheLmdbCtx *ctx = safe_calloc(1, sizeof(struct HcacheLmdbCtx));
+ struct HcacheLmdbCtx *ctx = mutt_mem_calloc(1, sizeof(struct HcacheLmdbCtx));
rc = mdb_env_create(&ctx->env);
if (rc != MDB_SUCCESS)
struct Header *mutt_new_header(void)
{
- struct Header *h = safe_calloc(1, sizeof(struct Header));
+ struct Header *h = mutt_mem_calloc(1, sizeof(struct Header));
#ifdef MIXMASTER
STAILQ_INIT(&h->chain);
#endif
}
if (History)
- h->hist = safe_calloc(History + 1, sizeof(char *));
+ h->hist = mutt_mem_calloc(History + 1, sizeof(char *));
h->cur = 0;
h->last = 0;
else if (~data & MUTT_GLOBALHOOK) /* NOT a global hook */
{
/* Hooks not allowing full patterns: Check syntax of regex */
- rx = safe_malloc(sizeof(regex_t));
+ rx = mutt_mem_malloc(sizeof(regex_t));
#ifdef MUTT_CRYPTHOOK
if ((rc = REGCOMP(rx, NONULL(pattern.data),
((data & (MUTT_CRYPTHOOK | MUTT_CHARSETHOOK | MUTT_ICONVHOOK)) ? REG_ICASE : 0))) != 0)
}
}
- ptr = safe_calloc(1, sizeof(struct Hook));
+ ptr = mutt_mem_calloc(1, sizeof(struct Hook));
ptr->type = data;
ptr->command = command.data;
ptr->pattern = pat;
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
mutt_buffer_init(&token);
TAILQ_FOREACH(tmp, &Hooks, entries)
{
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
mutt_buffer_init(&token);
memset(&cache, 0, sizeof(cache));
TAILQ_FOREACH(hook, &Hooks, entries)
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
mutt_buffer_init(&token);
TAILQ_FOREACH(hook, &Hooks, entries)
mutt_message(_("Authenticating (%s)..."), mech);
bufsize = ((olen * 2) > LONG_STRING) ? (olen * 2) : LONG_STRING;
- buf = safe_malloc(bufsize);
+ buf = mutt_mem_malloc(bufsize);
snprintf(buf, bufsize, "AUTHENTICATE %s", mech);
if (mutt_bit_isset(idata->capabilities, SASL_IR) && client_start)
if (len > bufsize)
{
bufsize = len;
- safe_realloc(&buf, bufsize);
+ mutt_mem_realloc(&buf, bufsize);
}
/* For sasl_decode64, the fourth parameter, outmax, doesn't
* include space for the trailing null */
if ((olen * 2) > bufsize)
{
bufsize = olen * 2;
- safe_realloc(&buf, bufsize);
+ mutt_mem_realloc(&buf, bufsize);
}
if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
{
if (state->entrylen + 1 == state->entrymax)
{
- safe_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256));
+ mutt_mem_realloc(&state->entry, sizeof(struct FolderFile) * (state->entrymax += 256));
memset(state->entry + state->entrylen, 0,
(sizeof(struct FolderFile) * (state->entrymax - state->entrylen)));
}
{
if (len == idata->blen)
{
- safe_realloc(&idata->buf, idata->blen + IMAP_CMD_BUFSIZE);
+ mutt_mem_realloc(&idata->buf, idata->blen + IMAP_CMD_BUFSIZE);
idata->blen = idata->blen + IMAP_CMD_BUFSIZE;
mutt_debug(3, "imap_cmd_step: grew buffer to %u bytes\n", idata->blen);
}
/* don't let one large string make cmd->buf hog memory forever */
if ((idata->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE))
{
- safe_realloc(&idata->buf, IMAP_CMD_BUFSIZE);
+ mutt_mem_realloc(&idata->buf, IMAP_CMD_BUFSIZE);
idata->blen = IMAP_CMD_BUFSIZE;
mutt_debug(3, "imap_cmd_step: shrank buffer to %u bytes\n", idata->blen);
}
if (Sort != SORT_ORDER)
{
hdrs = idata->ctx->hdrs;
- idata->ctx->hdrs = safe_malloc(idata->ctx->msgcount * sizeof(struct Header *));
+ idata->ctx->hdrs = mutt_mem_malloc(idata->ctx->msgcount * sizeof(struct Header *));
memcpy(idata->ctx->hdrs, hdrs, idata->ctx->msgcount * sizeof(struct Header *));
Sort = SORT_ORDER;
/* lame */
if (create)
{
- struct ImapStatus *scache = safe_calloc(1, sizeof(struct ImapStatus));
+ struct ImapStatus *scache = mutt_mem_calloc(1, sizeof(struct ImapStatus));
scache->name = (char *) mbox;
mutt_list_insert_tail(&idata->mboxcache, (char *) scache);
status = imap_mboxcache_get(idata, mbox, 0);
ctx->readonly = true;
ctx->hdrmax = count;
- ctx->hdrs = safe_calloc(count, sizeof(struct Header *));
- ctx->v2r = safe_calloc(count, sizeof(int));
+ ctx->hdrs = mutt_mem_calloc(count, sizeof(struct Header *));
+ ctx->v2r = mutt_mem_calloc(count, sizeof(int));
ctx->msgcount = 0;
if (count && (imap_read_headers(idata, 1, count) < 0))
if (Sort != SORT_ORDER)
{
hdrs = ctx->hdrs;
- ctx->hdrs = safe_malloc(ctx->msgcount * sizeof(struct Header *));
+ ctx->hdrs = mutt_mem_malloc(ctx->msgcount * sizeof(struct Header *));
memcpy(ctx->hdrs, hdrs, ctx->msgcount * sizeof(struct Header *));
Sort = SORT_ORDER;
*/
static struct ImapHeaderData *new_header_data(void)
{
- struct ImapHeaderData *d = safe_calloc(1, sizeof(struct ImapHeaderData));
+ struct ImapHeaderData *d = mutt_mem_calloc(1, sizeof(struct ImapHeaderData));
return d;
}
new_size = msn_count + 25;
if (!idata->msn_index)
- idata->msn_index = safe_calloc(new_size, sizeof(struct Header *));
+ idata->msn_index = mutt_mem_calloc(new_size, sizeof(struct Header *));
else
{
- safe_realloc(&idata->msn_index, sizeof(struct Header *) * new_size);
+ mutt_mem_realloc(&idata->msn_index, sizeof(struct Header *) * new_size);
memset(idata->msn_index + idata->msn_index_size, 0,
sizeof(struct Header *) * (new_size - idata->msn_index_size));
}
char *buf = NULL, *p = NULL;
int b, ch, k;
- p = buf = safe_malloc(u7len + u7len / 8 + 1);
+ p = buf = mutt_mem_malloc(u7len + u7len / 8 + 1);
for (; u7len; u7++, u7len--)
{
if (u8len)
*u8len = p - buf;
- safe_realloc(&buf, p - buf);
+ mutt_mem_realloc(&buf, p - buf);
if (u8)
*u8 = buf;
return buf;
* In the worst case we convert 2 chars to 7 chars. For example:
* "\x10&\x10&..." -> "&ABA-&-&ABA-&-...".
*/
- p = buf = safe_malloc((u8len / 2) * 7 + 6);
+ p = buf = mutt_mem_malloc((u8len / 2) * 7 + 6);
while (u8len)
{
*p++ = '\0';
if (u7len)
*u7len = p - buf;
- safe_realloc(&buf, p - buf);
+ mutt_mem_realloc(&buf, p - buf);
if (u7)
*u7 = buf;
return buf;
if ((mutt_strcasecmp(mx1, "INBOX") == 0) && (mutt_strcasecmp(mx2, "INBOX") == 0))
return 0;
- b1 = safe_malloc(strlen(mx1) + 1);
- b2 = safe_malloc(strlen(mx2) + 1);
+ b1 = mutt_mem_malloc(strlen(mx1) + 1);
+ b2 = mutt_mem_malloc(strlen(mx2) + 1);
imap_fix_path(NULL, mx1, b1, strlen(mx1) + 1);
imap_fix_path(NULL, mx2, b2, strlen(mx2) + 1);
*/
struct ImapData *imap_new_idata(void)
{
- struct ImapData *idata = safe_calloc(1, sizeof(struct ImapData));
+ struct ImapData *idata = mutt_mem_calloc(1, sizeof(struct ImapData));
idata->cmdbuf = mutt_buffer_new();
if (!idata->cmdbuf)
FREE(&idata);
idata->cmdslots = ImapPipelineDepth + 2;
- idata->cmds = safe_calloc(idata->cmdslots, sizeof(*idata->cmds));
+ idata->cmds = mutt_mem_calloc(idata->cmdslots, sizeof(*idata->cmds));
if (!idata->cmds)
{
mutt_buffer_free(&idata->cmdbuf);
break;
if (!*cur)
- *cur = safe_calloc(1, sizeof(struct MyVar));
+ *cur = mutt_mem_calloc(1, sizeof(struct MyVar));
if (!(*cur)->name)
(*cur)->name = safe_strdup(var);
}
}
- rx = safe_malloc(sizeof(regex_t));
+ rx = mutt_mem_malloc(sizeof(regex_t));
e = REGCOMP(rx, p, flags);
if (e != 0)
{
mbstate_t mbstate;
char *d = NULL;
- t = safe_calloc(1, sizeof(struct MbTable));
+ t = mutt_mem_calloc(1, sizeof(struct MbTable));
slen = mutt_strlen(s);
if (!slen)
return t;
t->orig_str = safe_strdup(s);
/* This could be more space efficient. However, being used on tiny
* strings (ToChars and StatusChars), the overhead is not great. */
- t->chars = safe_calloc(slen, sizeof(char *));
- d = t->segmented_str = safe_calloc(slen * 2, sizeof(char));
+ t->chars = mutt_mem_calloc(slen, sizeof(char *));
+ d = t->segmented_str = mutt_mem_calloc(slen * 2, sizeof(char));
memset(&mbstate, 0, sizeof(mbstate));
while (slen && (k = mbrtowc(NULL, s, slen, &mbstate)))
{
expnlen = mutt_strlen(expn.data);
tok->dsize = expnlen + mutt_strlen(tok->dptr) + 1;
- ptr = safe_malloc(tok->dsize);
+ ptr = mutt_mem_malloc(tok->dsize);
memcpy(ptr, expn.data, expnlen);
strcpy(ptr + expnlen, tok->dptr);
if (tok->destroy)
static struct RegexList *new_regex_list(void)
{
- return safe_calloc(1, sizeof(struct RegexList));
+ return mutt_mem_calloc(1, sizeof(struct RegexList));
}
int mutt_add_to_regex_list(struct RegexList **list, const char *s, int flags,
static struct ReplaceList *new_replace_list(void)
{
- return safe_calloc(1, sizeof(struct ReplaceList));
+ return mutt_mem_calloc(1, sizeof(struct ReplaceList));
}
static int add_to_replace_list(struct ReplaceList **list, const char *pat,
if (!buf->data || *buf->data == '\0')
continue;
- a = safe_malloc(sizeof(struct AttachMatch));
+ a = mutt_mem_malloc(sizeof(struct AttachMatch));
/* some cheap hacks that I expect to remove */
if (mutt_strcasecmp(buf->data, "any") == 0)
}
len = strlen(a->minor);
- tmpminor = safe_malloc(len + 3);
+ tmpminor = mutt_mem_malloc(len + 3);
strcpy(&tmpminor[1], a->minor);
tmpminor[0] = '^';
tmpminor[len + 1] = '$';
if (!tmp)
{
/* create a new alias */
- tmp = safe_calloc(1, sizeof(struct Alias));
+ tmp = mutt_mem_calloc(1, sizeof(struct Alias));
tmp->name = safe_strdup(buf->data);
/* give the main addressbook code a chance */
if (CurrentMenu == MENU_ALIAS)
int retval;
char *s = (char *) p->init;
- pp->regex = safe_calloc(1, sizeof(regex_t));
+ pp->regex = mutt_mem_calloc(1, sizeof(regex_t));
pp->pattern = safe_strdup((char *) p->init);
if (mutt_strcmp(p->option, "mask") != 0)
flags |= mutt_which_case((const char *) p->init);
/* If not found, add new slot */
else
{
- safe_realloc(&envlist, sizeof(char *) * (count + 2));
+ mutt_mem_realloc(&envlist, sizeof(char *) * (count + 2));
envlist[count] = safe_strdup(work);
envlist[count + 1] = NULL;
}
count++;
}
*save = NULL;
- safe_realloc(&envlist, sizeof(char *) * (count + 1));
+ mutt_mem_realloc(&envlist, sizeof(char *) * (count + 1));
return 0;
}
envp++;
extra_space = Matches_listsize - base_space;
extra_space *= 2;
space = base_space + extra_space;
- safe_realloc(&Matches, space * sizeof(char *));
+ mutt_mem_realloc(&Matches, space * sizeof(char *));
memset(&Matches[current + 1], 0, space - current);
Matches_listsize = space;
}
FREE(&nm_tags);
}
/* Allocate a new list, with sentinel. */
- nm_tags = safe_malloc((tag_count_1 + 1) * sizeof(char *));
+ nm_tags = mutt_mem_malloc((tag_count_1 + 1) * sizeof(char *));
nm_tags[tag_count_1] = NULL;
/* Get all the tags. */
mutt_buffer_init(&token);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
struct ListNode *np;
STAILQ_FOREACH(np, queries, entries)
mutt_buffer_init(&token);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
for (int i = 0; MuttVars[i].option; i++)
{
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
mutt_buffer_init(&token);
struct ListNode *np;
STAILQ_FOREACH(np, p, entries)
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
err.dptr = err.data;
Groups = mutt_hash_create(1031, 0);
/* now get FQDN. Use configured domain first, DNS next, then uname */
#ifdef DOMAIN
/* we have a compile-time domain name, use that for Hostname */
- Hostname = safe_malloc(mutt_strlen(DOMAIN) + mutt_strlen(ShortHostname) + 2);
+ Hostname = mutt_mem_malloc(mutt_strlen(DOMAIN) + mutt_strlen(ShortHostname) + 2);
sprintf(Hostname, "%s.%s", NONULL(ShortHostname), DOMAIN);
#else
if (!(getdnsdomainname(buffer, sizeof(buffer))))
{
- Hostname = safe_malloc(mutt_strlen(buffer) + mutt_strlen(ShortHostname) + 2);
+ Hostname = mutt_mem_malloc(mutt_strlen(buffer) + mutt_strlen(ShortHostname) + 2);
sprintf(Hostname, "%s.%s", NONULL(ShortHostname), buffer);
}
else
mutt_set_langinfo_charset();
mutt_set_charset(Charset);
- Matches = safe_calloc(Matches_listsize, sizeof(char *));
+ Matches = mutt_mem_calloc(Matches_listsize, sizeof(char *));
/* Set standard defaults */
for (int i = 0; MuttVars[i].option; i++)
{
struct Keymap *p = NULL;
- p = safe_calloc(1, sizeof(struct Keymap));
+ p = mutt_mem_calloc(1, sizeof(struct Keymap));
p->len = len;
- p->keys = safe_malloc(len * sizeof(keycode_t));
+ p->keys = mutt_mem_malloc(len * sizeof(keycode_t));
memcpy(p->keys, keys, len * sizeof(keycode_t));
return p;
}
int count = 0;
for (srcp = env; srcp && *srcp; srcp++)
count++;
- envlist = safe_calloc(count + 1, sizeof(char *));
+ envlist = mutt_mem_calloc(count + 1, sizeof(char *));
for (srcp = env, dstp = envlist; srcp && *srcp; srcp++, dstp++)
*dstp = safe_strdup(*srcp);
}
offset -= (sizeof(MMDF_SEP) - 1);
/* allocate space for the new offsets */
- newOffset = safe_calloc(ctx->msgcount - first, sizeof(struct MUpdate));
- oldOffset = safe_calloc(ctx->msgcount - first, sizeof(struct MUpdate));
+ newOffset = mutt_mem_calloc(ctx->msgcount - first, sizeof(struct MUpdate));
+ oldOffset = mutt_mem_calloc(ctx->msgcount - first, sizeof(struct MUpdate));
if (!ctx->quiet)
{
mutt_buffer_addstr(b, scratch);
}
FREE(s);
- *s = b->data ? b->data : safe_calloc(1, 1);
+ *s = b->data ? b->data : mutt_mem_calloc(1, 1);
FREE(&b);
return 0;
}
struct Menu *mutt_new_menu(int menu)
{
- struct Menu *p = safe_calloc(1, sizeof(struct Menu));
+ struct Menu *p = mutt_mem_calloc(1, sizeof(struct Menu));
if ((menu < 0) || (menu >= MENU_MAX))
menu = MENU_GENERIC;
if (MenuStackCount >= MenuStackLen)
{
MenuStackLen += 5;
- safe_realloc(&MenuStack, MenuStackLen * sizeof(struct Menu *));
+ mutt_mem_realloc(&MenuStack, MenuStackLen * sizeof(struct Menu *));
}
MenuStack[MenuStackCount++] = menu;
{
newmax = i + 128;
j = mhs->flags ? mhs->max + 1 : 0;
- safe_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1));
+ mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1));
while (j <= newmax)
mhs->flags[j++] = 0;
else
h->path = safe_strdup(de->d_name);
- entry = safe_calloc(1, sizeof(struct Maildir));
+ entry = mutt_mem_calloc(1, sizeof(struct Maildir));
entry->h = h;
entry->inode = de->d_ino;
**last = entry;
if (!ctx->data)
{
- ctx->data = safe_calloc(1, sizeof(struct MhData));
+ ctx->data = mutt_mem_calloc(1, sizeof(struct MhData));
}
data = mh_data(ctx);
{
struct Buffer *b = NULL;
- b = safe_malloc(sizeof(struct Buffer));
+ b = mutt_mem_malloc(sizeof(struct Buffer));
mutt_buffer_init(b);
{
size_t offset = buf->dptr - buf->data;
buf->dsize += (len < 128) ? 128 : len + 1;
- safe_realloc(&buf->data, buf->dsize);
+ mutt_mem_realloc(&buf->data, buf->dsize);
buf->dptr = buf->data + offset;
}
if (!buf->dptr)
{
blen = 128;
buf->dsize += blen;
- safe_realloc(&buf->data, buf->dsize);
+ mutt_mem_realloc(&buf->data, buf->dsize);
buf->dptr = buf->data + doff;
}
len = vsnprintf(buf->dptr, blen, fmt, ap);
if (blen < 128)
blen = 128;
buf->dsize += blen;
- safe_realloc(&buf->data, buf->dsize);
+ mutt_mem_realloc(&buf->data, buf->dsize);
buf->dptr = buf->data + doff;
len = vsnprintf(buf->dptr, len, fmt, ap_retry);
}
if (!s)
{
- s = safe_malloc(STRING);
+ s = mutt_mem_malloc(STRING);
*size = STRING;
}
/* There wasn't room for the line -- increase ``s'' */
offset = *size - 1; /* overwrite the terminating 0 */
*size += STRING;
- safe_realloc(&s, *size);
+ mutt_mem_realloc(&s, *size);
}
}
}
*/
static struct Hash *new_hash(int nelem)
{
- struct Hash *table = safe_calloc(1, sizeof(struct Hash));
+ struct Hash *table = mutt_mem_calloc(1, sizeof(struct Hash));
if (nelem == 0)
nelem = 2;
table->nelem = nelem;
- table->table = safe_calloc(nelem, sizeof(struct HashElem *));
+ table->table = mutt_mem_calloc(nelem, sizeof(struct HashElem *));
return table;
}
struct HashElem *ptr = NULL;
unsigned int h;
- ptr = safe_malloc(sizeof(struct HashElem));
+ ptr = mutt_mem_malloc(sizeof(struct HashElem));
h = table->gen_hash(key, table->nelem);
ptr->key = key;
ptr->data = data;
*/
struct ListNode *mutt_list_insert_head(struct ListHead *h, char *s)
{
- struct ListNode *np = safe_calloc(1, sizeof(struct ListNode));
+ struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode));
np->data = s;
STAILQ_INSERT_HEAD(h, np, entries);
return np;
*/
struct ListNode *mutt_list_insert_tail(struct ListHead *h, char *s)
{
- struct ListNode *np = safe_calloc(1, sizeof(struct ListNode));
+ struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode));
np->data = s;
STAILQ_INSERT_TAIL(h, np, entries);
return np;
*/
struct ListNode *mutt_list_insert_after(struct ListHead *h, struct ListNode *n, char *s)
{
- struct ListNode *np = safe_calloc(1, sizeof(struct ListNode));
+ struct ListNode *np = mutt_mem_calloc(1, sizeof(struct ListNode));
np->data = s;
STAILQ_INSERT_AFTER(h, n, np, entries);
return np;
if (i >= wbuflen)
{
wbuflen = i + 20;
- safe_realloc(&wbuf, wbuflen * sizeof(*wbuf));
+ mutt_mem_realloc(&wbuf, wbuflen * sizeof(*wbuf));
}
wbuf[i++] = wc;
}
if (i >= wbuflen)
{
wbuflen = i + 20;
- safe_realloc(&wbuf, wbuflen * sizeof(*wbuf));
+ mutt_mem_realloc(&wbuf, wbuflen * sizeof(*wbuf));
}
wbuf[i++] = ReplacementChar;
buf++;
* @note If any of the allocators fail, the user is notified and the program is
* stopped immediately.
*
- * | Function | Description
- * | :------------- | :-----------------------------------
- * | safe_calloc() | Allocate zeroed memory on the heap
- * | safe_free() | Release memory allocated on the heap
- * | safe_malloc() | Allocate memory on the heap
- * | safe_realloc() | Resize a block of memory on the heap
+ * | Function | Description
+ * | :----------------- | :-----------------------------------
+ * | mutt_mem_calloc() | Allocate zeroed memory on the heap
+ * | mutt_mem_free() | Release memory allocated on the heap
+ * | mutt_mem_malloc() | Allocate memory on the heap
+ * | mutt_mem_realloc() | Resize a block of memory on the heap
*/
#include "config.h"
#include "message.h"
/**
- * safe_calloc - Allocate zeroed memory on the heap
+ * mutt_mem_calloc - Allocate zeroed memory on the heap
* @param nmemb Number of blocks
* @param size Size of blocks
* @retval ptr Memory on the heap
* @note This function will never return NULL.
* It will print and error and exit the program.
*
- * The caller should call safe_free() to release the memory
+ * The caller should call mutt_mem_free() to release the memory
*/
-void *safe_calloc(size_t nmemb, size_t size)
+void *mutt_mem_calloc(size_t nmemb, size_t size)
{
void *p = NULL;
}
/**
- * safe_free - Release memory allocated on the heap
+ * mutt_mem_free - Release memory allocated on the heap
* @param ptr Memory to release
*/
-void safe_free(void *ptr)
+void mutt_mem_free(void *ptr)
{
if (!ptr)
return;
}
/**
- * safe_malloc - Allocate memory on the heap
+ * mutt_mem_malloc - Allocate memory on the heap
* @param size Size of block to allocate
* @retval ptr Memory on the heap
*
* @note This function will never return NULL.
* It will print and error and exit the program.
*
- * The caller should call safe_free() to release the memory
+ * The caller should call mutt_mem_free() to release the memory
*/
-void *safe_malloc(size_t size)
+void *mutt_mem_malloc(size_t size)
{
void *p = NULL;
}
/**
- * safe_realloc - Resize a block of memory on the heap
+ * mutt_mem_realloc - Resize a block of memory on the heap
* @param ptr Memory block to resize
* @param size New size
*
*
* If the new size is zero, the block will be freed.
*/
-void safe_realloc(void *ptr, size_t size)
+void mutt_mem_realloc(void *ptr, size_t size)
{
void *r = NULL;
void **p = (void **) ptr;
#define mutt_array_size(x) (sizeof(x) / sizeof((x)[0]))
-void *safe_calloc(size_t nmemb, size_t size);
-void safe_free(void *ptr);
-void *safe_malloc(size_t size);
-void safe_realloc(void *ptr, size_t size);
+void *mutt_mem_calloc(size_t nmemb, size_t size);
+void mutt_mem_free(void *ptr);
+void *mutt_mem_malloc(size_t size);
+void mutt_mem_realloc(void *ptr, size_t size);
-#define FREE(x) safe_free(x)
+#define FREE(x) mutt_mem_free(x)
#endif /* _MUTT_MEMORY_H */
if (!s || !*s)
return 0;
l = strlen(s) + 1;
- p = safe_malloc(l);
+ p = mutt_mem_malloc(l);
memcpy(p, s, l);
return p;
}
size_t sz = strlen(item);
size_t ssz = *str ? strlen(*str) : 0;
- safe_realloc(str, ssz + ((ssz && sep) ? 1 : 0) + sz + 1);
+ mutt_mem_realloc(str, ssz + ((ssz && sep) ? 1 : 0) + sz + 1);
p = *str + ssz;
if (sep && ssz)
*p++ = sep;
{
if (!p || !*p)
return;
- safe_realloc(p, strlen(*p) + 1);
+ mutt_mem_realloc(p, strlen(*p) + 1);
}
/**
len = strlen(begin);
}
- p = safe_malloc(len + 1);
+ p = mutt_mem_malloc(len + 1);
memcpy(p, begin, len);
p[len] = '\0';
return p;
}
}
- mailbox = safe_malloc(mutt_strlen(local_user) + mutt_strlen(local_domain) + 2);
+ mailbox = mutt_mem_malloc(mutt_strlen(local_user) + mutt_strlen(local_domain) + 2);
sprintf(mailbox, "%s@%s", NONULL(local_user), NONULL(local_domain));
cleanup:
}
#endif /* HAVE_LIBIDN */
- mailbox = safe_malloc(mutt_strlen(intl_user) + mutt_strlen(intl_domain) + 2);
+ mailbox = mutt_mem_malloc(mutt_strlen(intl_user) + mutt_strlen(intl_domain) + 2);
sprintf(mailbox, "%s@%s", NONULL(intl_user), NONULL(intl_domain));
cleanup:
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
if (lua_gettop(l) == 0)
{
mutt_buffer_init(&token);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
if (mutt_parse_rc_line(buffer, &token, &err))
{
if (!uri)
return NULL;
- data = safe_calloc(1, sizeof(struct NmCtxData));
+ data = mutt_mem_calloc(1, sizeof(struct NmCtxData));
mutt_debug(1, "nm: initialize context data %p\n", (void *) data);
data->db_limit = NmDbLimit;
if (!id)
return NULL;
sz = strlen(id) + 3;
- mid = safe_malloc(sz);
+ mid = mutt_mem_malloc(sz);
snprintf(mid, sz, "<%s>", id);
return mid;
id = notmuch_message_get_message_id(msg);
- h->data = safe_calloc(1, sizeof(struct NmHdrData));
+ h->data = mutt_mem_calloc(1, sizeof(struct NmHdrData));
h->free_cb = deinit_header;
/*
{
char *new_tag_transformed = mutt_hash_find(TagTransforms, new_tag);
- struct TagNode *np = safe_calloc(1, sizeof(struct TagNode));
+ struct TagNode *np = mutt_mem_calloc(1, sizeof(struct TagNode));
np->name = safe_strdup(new_tag);
np->hidden = false;
if (new_tag_transformed)
/* If this pattern needs more matches, expand pmatch. */
if (l->nmatch > nmatch)
{
- safe_realloc(&pmatch, l->nmatch * sizeof(regmatch_t));
+ mutt_mem_realloc(&pmatch, l->nmatch * sizeof(regmatch_t));
nmatch = l->nmatch;
}
struct Regex *mutt_compile_regex(const char *s, int flags)
{
- struct Regex *pp = safe_calloc(1, sizeof(struct Regex));
+ struct Regex *pp = mutt_mem_calloc(1, sizeof(struct Regex));
pp->pattern = safe_strdup(s);
- pp->regex = safe_calloc(1, sizeof(regex_t));
+ pp->regex = mutt_mem_calloc(1, sizeof(regex_t));
if (REGCOMP(pp->regex, NONULL(s), flags) != 0)
mutt_free_regex(&pp);
/* If this pattern needs more matches, expand pmatch. */
if (l->nmatch > nmatch)
{
- safe_realloc(&pmatch, l->nmatch * sizeof(regmatch_t));
+ mutt_mem_realloc(&pmatch, l->nmatch * sizeof(regmatch_t));
nmatch = l->nmatch;
}
return NULL;
if (!ctx)
- ctx = safe_malloc(sizeof(struct Context));
+ ctx = mutt_mem_malloc(sizeof(struct Context));
memset(ctx, 0, sizeof(struct Context));
ctx->path = safe_strdup(path);
return NULL;
}
- msg = safe_calloc(1, sizeof(struct Message));
+ msg = mutt_mem_calloc(1, sizeof(struct Message));
msg->write = true;
if (hdr)
return NULL;
}
- msg = safe_calloc(1, sizeof(struct Message));
+ msg = mutt_mem_calloc(1, sizeof(struct Message));
if (ctx->mx_ops->open_msg(ctx, msg, msgno))
FREE(&msg);
if (ctx->hdrs)
{
- safe_realloc(&ctx->hdrs, sizeof(struct Header *) * (ctx->hdrmax += 25));
- safe_realloc(&ctx->v2r, sizeof(int) * ctx->hdrmax);
+ mutt_mem_realloc(&ctx->hdrs, sizeof(struct Header *) * (ctx->hdrmax += 25));
+ mutt_mem_realloc(&ctx->v2r, sizeof(int) * ctx->hdrmax);
}
else
{
- ctx->hdrs = safe_calloc((ctx->hdrmax += 25), sizeof(struct Header *));
- ctx->v2r = safe_calloc(ctx->hdrmax, sizeof(int));
+ ctx->hdrs = mutt_mem_calloc((ctx->hdrmax += 25), sizeof(struct Header *));
+ ctx->v2r = mutt_mem_calloc(ctx->hdrmax, sizeof(int));
}
for (int i = ctx->msgcount; i < ctx->hdrmax; i++)
{
if (!oppenc_mode && self_encrypt && *self_encrypt)
{
keylist_size = mutt_strlen(*keylist);
- safe_realloc(keylist, keylist_size + mutt_strlen(self_encrypt) + 2);
+ mutt_mem_realloc(keylist, keylist_size + mutt_strlen(self_encrypt) + 2);
sprintf(*keylist + keylist_size, " %s", self_encrypt);
}
else
{
if ((*n % 5) == 0)
- safe_realloc(signatures, (*n + 6) * sizeof(struct Body **));
+ mutt_mem_realloc(signatures, (*n + 6) * sizeof(struct Body **));
(*signatures)[(*n)++] = a;
}
{
char *tstr = NULL;
- tstr = safe_malloc(len + 1);
+ tstr = mutt_mem_malloc(len + 1);
memcpy(tstr, buf, len);
tstr[len] = 0;
{
struct CryptKeyInfo *k = NULL;
- k = safe_calloc(1, sizeof(*k));
+ k = mutt_mem_calloc(1, sizeof(*k));
k->kobj = key->kobj;
gpgme_key_ref(key->kobj);
k->idx = key->idx;
else
err = gpgme_get_key(context, buf, &key, 0);
- safe_realloc(&rset, sizeof(*rset) * (rset_n + 1));
+ mutt_mem_realloc(&rset, sizeof(*rset) * (rset_n + 1));
if (!err)
rset[rset_n++] = key;
else
}
/* NULL terminate. */
- safe_realloc(&rset, sizeof(*rset) * (rset_n + 1));
+ mutt_mem_realloc(&rset, sizeof(*rset) * (rset_n + 1));
rset[rset_n++] = NULL;
if (context)
return;
is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
- buf = safe_malloc(strlen(prefix) + strlen(s) * 4 + 2);
+ buf = mutt_mem_malloc(strlen(prefix) + strlen(s) * 4 + 2);
strcpy(buf, prefix);
p = buf + strlen(buf);
if (is_pgp && strlen(s) == 40)
n = s - string;
if (!n)
return NULL; /* empty key */
- array->key = safe_malloc(n + 1);
+ array->key = mutt_mem_malloc(n + 1);
p = array->key;
memcpy(p, string, n); /* fixme: trim trailing spaces */
p[n] = 0;
if (!n || (n & 1))
return NULL; /* empty or odd number of digits */
n /= 2;
- p = safe_malloc(n + 1);
+ p = mutt_mem_malloc(n + 1);
array->value = (char *) p;
for (s1 = string; n; s1 += 2, n--)
sscanf(s1, "%2hhx", (unsigned char *) p++);
n++;
}
- p = safe_malloc(n + 1);
+ p = mutt_mem_malloc(n + 1);
array->value = (char *) p;
for (s = string; n; s++, n--)
{
size_t arrayidx, arraysize;
arraysize = 7; /* C,ST,L,O,OU,CN,email */
- array = safe_malloc((arraysize + 1) * sizeof(*array));
+ array = mutt_mem_malloc((arraysize + 1) * sizeof(*array));
arrayidx = 0;
while (*string)
{
break; /* ready */
if (arrayidx >= arraysize)
{
- /* neomutt lacks a real safe_realloc - so we need to copy */
+ /* neomutt lacks a real mutt_mem_realloc - so we need to copy */
struct DnArray *a2 = NULL;
arraysize += 5;
- a2 = safe_malloc((arraysize + 1) * sizeof(*array));
+ a2 = mutt_mem_malloc((arraysize + 1) * sizeof(*array));
for (int i = 0; i < arrayidx; i++)
{
a2[i].key = array[i].key;
n++; /* delimiter or end of string */
}
n++; /* make sure to allocate at least one byte */
- pattern = p = safe_calloc(1, n);
+ pattern = p = mutt_mem_calloc(1, n);
STAILQ_FOREACH(np, list, entries)
{
s = np->data;
if (!n)
goto no_pgphints;
- char **patarr = safe_calloc(n + 1, sizeof(*patarr));
+ char **patarr = mutt_mem_calloc(n + 1, sizeof(*patarr));
n = 0;
STAILQ_FOREACH(np, hints, entries)
{
for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
{
- k = safe_calloc(1, sizeof(*k));
+ k = mutt_mem_calloc(1, sizeof(*k));
k->kobj = key;
gpgme_key_ref(k->kobj);
k->idx = idx;
for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
{
- k = safe_calloc(1, sizeof(*k));
+ k = mutt_mem_calloc(1, sizeof(*k));
k->kobj = key;
gpgme_key_ref(k->kobj);
k->idx = idx;
if (i == keymax)
{
keymax += 20;
- safe_realloc(&key_table, sizeof(struct CryptKeyInfo *) * keymax);
+ mutt_mem_realloc(&key_table, sizeof(struct CryptKeyInfo *) * keymax);
}
key_table[i++] = k;
mutt_str_replace(&l->dflt, resp);
else
{
- l = safe_malloc(sizeof(struct CryptCache));
+ l = mutt_mem_malloc(sizeof(struct CryptCache));
l->next = id_defaults;
id_defaults = l;
l->what = safe_strdup(whatfor);
bypass_selection:
keylist_size += mutt_strlen(keyID) + 4 + 1;
- safe_realloc(&keylist, keylist_size);
+ mutt_mem_realloc(&keylist, keylist_size);
sprintf(keylist + keylist_used, "%s0x%s%s", keylist_used ? " " : "",
keyID, forced_valid ? "!" : "");
keylist_used = mutt_strlen(keylist);
*/
void crypto_module_register(struct CryptModuleSpecs *specs)
{
- struct CryptModule *module = safe_calloc(1, sizeof(struct CryptModule));
+ struct CryptModule *module = mutt_mem_calloc(1, sizeof(struct CryptModule));
module->specs = specs;
STAILQ_INSERT_HEAD(&modules, module, entries);
}
char *ob = NULL;
size_t ibl, obl;
- buf = safe_malloc(n + 1);
+ buf = mutt_mem_malloc(n + 1);
ib = uid;
ibl = d - uid + 1;
ob = buf;
mutt_debug(2, "user ID: %s\n", NONULL(p));
- uid = safe_calloc(1, sizeof(struct PgpUid));
+ uid = mutt_mem_calloc(1, sizeof(struct PgpUid));
fix_uid(p);
uid->addr = safe_strdup(p);
uid->trust = trust;
/* merge temp key back into real key */
if (!(is_uid || is_fpr || (*is_subkey && option(OPT_PGP_IGNORE_SUBKEYS))))
- k = safe_malloc(sizeof(*k));
+ k = mutt_mem_malloc(sizeof(*k));
memcpy(k, &tmp, sizeof(*k));
/* fixup parentship of uids after merging the temp key into
* the real key */
bypass_selection:
keylist_size += mutt_strlen(keyID) + 4;
- safe_realloc(&keylist, keylist_size);
+ mutt_mem_realloc(&keylist, keylist_size);
sprintf(keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", keyID);
keylist_used = mutt_strlen(keylist);
if (i == keymax)
{
keymax += 5;
- safe_realloc(&KeyTable, sizeof(struct PgpUid *) * keymax);
+ mutt_mem_realloc(&KeyTable, sizeof(struct PgpUid *) * keymax);
}
KeyTable[i++] = a;
mutt_str_replace(&l->dflt, resp);
else
{
- l = safe_malloc(sizeof(struct PgpCache));
+ l = mutt_mem_malloc(sizeof(struct PgpCache));
l->next = id_defaults;
id_defaults = l;
l->what = safe_strdup(whatfor);
for (; up; up = up->next)
{
- *lp = safe_calloc(1, sizeof(struct PgpUid));
+ *lp = mutt_mem_calloc(1, sizeof(struct PgpUid));
(*lp)->trust = up->trust;
(*lp)->flags = up->flags;
(*lp)->addr = safe_strdup(up->addr);
static inline struct PgpKeyInfo *pgp_new_keyinfo(void)
{
- return safe_calloc(1, sizeof(struct PgpKeyInfo));
+ return mutt_mem_calloc(1, sizeof(struct PgpKeyInfo));
}
#endif /* CRYPT_BACKEND_CLASSIC_PGP */
if (!plen)
{
plen = CHUNKSIZE;
- pbuf = safe_malloc(plen);
+ pbuf = mutt_mem_malloc(plen);
}
if (fread(&ctb, 1, 1, fp) < 1)
if (!key)
return NULL;
- copy = safe_calloc(1, sizeof(struct SmimeKey));
+ copy = mutt_mem_calloc(1, sizeof(struct SmimeKey));
copy->email = safe_strdup(key->email);
copy->hash = safe_strdup(key->hash);
copy->label = safe_strdup(key->label);
if (table_index == table_size)
{
table_size += 5;
- safe_realloc(&table, sizeof(struct SmimeKey *) * table_size);
+ mutt_mem_realloc(&table, sizeof(struct SmimeKey *) * table_size);
}
table[table_index++] = key;
char *pend = NULL, *p = NULL;
int field = 0;
- key = safe_calloc(1, sizeof(struct SmimeKey));
+ key = mutt_mem_calloc(1, sizeof(struct SmimeKey));
for (p = buf; p; p = pend)
{
keyID = key->hash;
keylist_size += mutt_strlen(keyID) + 2;
- safe_realloc(&keylist, keylist_size);
+ mutt_mem_realloc(&keylist, keylist_size);
sprintf(keylist + keylist_used, "%s%s", keylist_used ? " " : "", keyID);
keylist_used = mutt_strlen(keylist);
if (copy && buffer && num)
{
(*num) = count;
- *buffer = safe_calloc(count, sizeof(char *));
+ *buffer = mutt_mem_calloc(count, sizeof(char *));
count = 0;
rewind(fpout);
len = mutt_strlen(email);
if (len && (email[len - 1] == '\n'))
email[len - 1] = '\0';
- (*buffer)[count] = safe_calloc(mutt_strlen(email) + 1, sizeof(char));
+ (*buffer)[count] = mutt_mem_calloc(mutt_strlen(email) + 1, sizeof(char));
strncpy((*buffer)[count], email, mutt_strlen(email));
count++;
}
if (mutt_strncasecmp("sha", md, 3) == 0)
{
l = strlen(md) + 2;
- micalg = safe_malloc(l);
+ micalg = mutt_mem_malloc(l);
snprintf(micalg, l, "sha-%s", md + 3);
}
else
{
int len = strlen(group) + 1;
/* create NntpData structure and add it to hash */
- nntp_data = safe_calloc(1, sizeof(struct NntpData) + len);
+ nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len);
nntp_data->group = (char *) nntp_data + sizeof(struct NntpData);
strfcpy(nntp_data->group, group, len);
nntp_data->nserv = nserv;
if (nserv->groups_num >= nserv->groups_max)
{
nserv->groups_max *= 2;
- safe_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data));
+ mutt_mem_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data));
}
nserv->groups_list[nserv->groups_num++] = nntp_data;
}
FREE(&nntp_data->newsrc_ent);
}
- line = safe_malloc(sb.st_size + 1);
+ line = mutt_mem_malloc(sb.st_size + 1);
while (sb.st_size && fgets(line, sb.st_size + 1, nserv->newsrc_fp))
{
char *b = NULL, *h = NULL, *p = NULL;
while (*b)
if (*b++ == ',')
j++;
- nntp_data->newsrc_ent = safe_calloc(j, sizeof(struct NewsrcEntry));
+ nntp_data->newsrc_ent = mutt_mem_calloc(j, sizeof(struct NewsrcEntry));
nntp_data->subscribed = subs;
/* parse entries */
if (nntp_data->last_message == 0)
nntp_data->last_message = nntp_data->newsrc_ent[j - 1].last;
nntp_data->newsrc_len = j;
- safe_realloc(&nntp_data->newsrc_ent, j * sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, j * sizeof(struct NewsrcEntry));
nntp_group_unread_stat(nntp_data);
mutt_debug(2, "nntp_newsrc_parse: %s\n", nntp_data->group);
}
if (!entries)
{
entries = 5;
- nntp_data->newsrc_ent = safe_calloc(entries, sizeof(struct NewsrcEntry));
+ nntp_data->newsrc_ent = mutt_mem_calloc(entries, sizeof(struct NewsrcEntry));
}
/* Set up to fake initial sequence from 1 to the article before the
if (nntp_data->newsrc_len >= entries)
{
entries *= 2;
- safe_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry));
}
nntp_data->newsrc_ent[nntp_data->newsrc_len].first = first;
nntp_data->newsrc_ent[nntp_data->newsrc_len].last = last - 1;
if (nntp_data->newsrc_len >= entries)
{
entries++;
- safe_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, entries * sizeof(struct NewsrcEntry));
}
nntp_data->newsrc_ent[nntp_data->newsrc_len].first = first;
nntp_data->newsrc_ent[nntp_data->newsrc_len].last = nntp_data->last_loaded;
nntp_data->newsrc_len++;
}
- safe_realloc(&nntp_data->newsrc_ent, nntp_data->newsrc_len * sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, nntp_data->newsrc_len * sizeof(struct NewsrcEntry));
if (save_sort != Sort)
{
return -1;
buflen = 10 * LONG_STRING;
- buf = safe_calloc(1, buflen);
+ buf = mutt_mem_calloc(1, buflen);
off = 0;
/* we will generate full newsrc here */
if (off + strlen(nntp_data->group) + 3 > buflen)
{
buflen *= 2;
- safe_realloc(&buf, buflen);
+ mutt_mem_realloc(&buf, buflen);
}
snprintf(buf + off, buflen - off, "%s%c ", nntp_data->group,
nntp_data->subscribed ? ':' : '!');
if (off + LONG_STRING > buflen)
{
buflen *= 2;
- safe_realloc(&buf, buflen);
+ mutt_mem_realloc(&buf, buflen);
}
if (j)
buf[off++] = ',';
return 0;
buflen = 10 * LONG_STRING;
- buf = safe_calloc(1, buflen);
+ buf = mutt_mem_calloc(1, buflen);
snprintf(buf, buflen, "%lu\n", (unsigned long) nserv->newgroups_time);
off = strlen(buf);
if (off + strlen(nntp_data->group) + (nntp_data->desc ? strlen(nntp_data->desc) : 0) + 50 > buflen)
{
buflen *= 2;
- safe_realloc(&buf, buflen);
+ mutt_mem_realloc(&buf, buflen);
}
snprintf(buf + off, buflen - off, "%s %d %d %c%s%s\n", nntp_data->group,
nntp_data->last_message, nntp_data->first_message,
}
/* new news server */
- nserv = safe_calloc(1, sizeof(struct NntpServer));
+ nserv = mutt_mem_calloc(1, sizeof(struct NntpServer));
nserv->conn = conn;
nserv->groups_hash = mutt_hash_create(1009, 0);
nserv->groups_max = 16;
- nserv->groups_list = safe_malloc(nserv->groups_max * sizeof(nntp_data));
+ nserv->groups_list = mutt_mem_malloc(nserv->groups_max * sizeof(nntp_data));
rc = nntp_open_connection(nserv);
nntp_data->subscribed = true;
if (!nntp_data->newsrc_ent)
{
- nntp_data->newsrc_ent = safe_calloc(1, sizeof(struct NewsrcEntry));
+ nntp_data->newsrc_ent = mutt_mem_calloc(1, sizeof(struct NewsrcEntry));
nntp_data->newsrc_len = 1;
nntp_data->newsrc_ent[0].first = 1;
nntp_data->newsrc_ent[0].last = 0;
if (nntp_data->newsrc_ent)
{
- safe_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry));
nntp_data->newsrc_len = 1;
nntp_data->newsrc_ent[0].first = 1;
nntp_data->newsrc_ent[0].last = nntp_data->last_message;
if (nntp_data->newsrc_ent)
{
- safe_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry));
nntp_data->newsrc_len = 1;
nntp_data->newsrc_ent[0].first = 1;
nntp_data->newsrc_ent[0].last = nntp_data->first_message - 1;
if (nserv->overview_fmt)
FREE(&nserv->overview_fmt);
- nserv->overview_fmt = safe_malloc(buflen);
+ nserv->overview_fmt = mutt_mem_malloc(buflen);
while (true)
{
if (buflen - off < LONG_STRING)
{
buflen *= 2;
- safe_realloc(&nserv->overview_fmt, buflen);
+ mutt_mem_realloc(&nserv->overview_fmt, buflen);
}
chunk = mutt_socket_readln(nserv->overview_fmt + off, buflen - off, conn);
}
}
nserv->overview_fmt[off++] = '\0';
- safe_realloc(&nserv->overview_fmt, off);
+ mutt_mem_realloc(&nserv->overview_fmt, off);
}
}
return 0;
return 1;
}
- line = safe_malloc(sizeof(buf));
+ line = mutt_mem_malloc(sizeof(buf));
rc = 0;
while (true)
off = 0;
}
- safe_realloc(&line, off + sizeof(buf));
+ mutt_mem_realloc(&line, off + sizeof(buf));
}
FREE(&line);
funct(NULL, data);
hdr->read = false;
hdr->old = false;
hdr->deleted = false;
- hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData));
+ hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData));
NHDR(hdr)->article_num = anum;
if (fc->restore)
hdr->changed = true;
fc.first = first;
fc.last = last;
fc.restore = restore;
- fc.messages = safe_calloc(last - first + 1, sizeof(unsigned char));
+ fc.messages = mutt_mem_calloc(last - first + 1, sizeof(unsigned char));
#ifdef USE_HCACHE
fc.hc = hc;
#endif
hdr->read = false;
hdr->old = false;
hdr->deleted = false;
- hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData));
+ hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData));
NHDR(hdr)->article_num = current;
if (restore)
hdr->changed = true;
nntp_data->last_cached = 0;
if (nntp_data->newsrc_len)
{
- safe_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry));
+ mutt_mem_realloc(&nntp_data->newsrc_ent, sizeof(struct NewsrcEntry));
nntp_data->newsrc_len = 1;
nntp_data->newsrc_ent[0].first = 1;
nntp_data->newsrc_ent[0].last = 0;
if (NntpContext && nntp_data->last_message - first + 1 > NntpContext)
first = nntp_data->last_message - NntpContext + 1;
- messages = safe_calloc(nntp_data->last_loaded - first + 1, sizeof(unsigned char));
+ messages = mutt_mem_calloc(nntp_data->last_loaded - first + 1, sizeof(unsigned char));
hc = nntp_hcache_open(nntp_data);
nntp_hcache_update(nntp_data, hc);
#endif
ctx->msgcount++;
hdr->read = false;
hdr->old = false;
- hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData));
+ hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData));
NHDR(hdr)->article_num = anum;
nntp_article_status(ctx, hdr, NULL, anum);
if (!hdr->read)
if (ctx->msgcount == ctx->hdrmax)
mx_alloc_memory(ctx);
hdr = ctx->hdrs[ctx->msgcount] = mutt_new_header();
- hdr->data = safe_calloc(1, sizeof(struct NntpHeaderData));
+ hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData));
hdr->env = mutt_read_rfc822_header(fp, hdr, 0, 0);
mutt_file_fclose(&fp);
unlink(tempfile);
if (cc->num >= cc->max)
{
cc->max *= 2;
- safe_realloc(&cc->child, sizeof(anum_t) * cc->max);
+ mutt_mem_realloc(&cc->child, sizeof(anum_t) * cc->max);
}
cc->child[cc->num++] = anum;
return 0;
cc.ctx = ctx;
cc.num = 0;
cc.max = 10;
- cc.child = safe_malloc(sizeof(anum_t) * cc.max);
+ cc.child = mutt_mem_malloc(sizeof(anum_t) * cc.max);
/* fetch numbers of child messages */
snprintf(buf, sizeof(buf), "XPAT References %d-%d *%s*\r\n",
if (!*quote_list)
{
- class = safe_calloc(1, sizeof(struct QClass));
+ class = mutt_mem_calloc(1, sizeof(struct QClass));
class->color = ColorQuote[0];
*quote_list = class;
}
if (!tmp)
{
/* add a node above q_list */
- tmp = safe_calloc(1, sizeof(struct QClass));
- tmp->prefix = safe_calloc(1, length + 1);
+ tmp = mutt_mem_calloc(1, sizeof(struct QClass));
+ tmp->prefix = mutt_mem_calloc(1, length + 1);
strncpy(tmp->prefix, qptr, length);
tmp->length = length;
if (!tmp)
{
/* add a node above q_list */
- tmp = safe_calloc(1, sizeof(struct QClass));
- tmp->prefix = safe_calloc(1, length + 1);
+ tmp = mutt_mem_calloc(1, sizeof(struct QClass));
+ tmp->prefix = mutt_mem_calloc(1, length + 1);
strncpy(tmp->prefix, qptr, length);
tmp->length = length;
/* still not found so far: add it as a sibling to the current node */
if (!class)
{
- tmp = safe_calloc(1, sizeof(struct QClass));
- tmp->prefix = safe_calloc(1, length + 1);
+ tmp = mutt_mem_calloc(1, sizeof(struct QClass));
+ tmp->prefix = mutt_mem_calloc(1, length + 1);
strncpy(tmp->prefix, qptr, length);
tmp->length = length;
if (!class)
{
/* not found so far: add it as a top level class */
- class = safe_calloc(1, sizeof(struct QClass));
- class->prefix = safe_calloc(1, length + 1);
+ class = mutt_mem_calloc(1, sizeof(struct QClass));
+ class->prefix = mutt_mem_calloc(1, length + 1);
strncpy(class->prefix, qptr, length);
class->length = length;
new_class_color(class, q_level);
if (line_info[i].chunks)
{
line_info[i].chunks = 0;
- safe_realloc(&(line_info[n].syntax), sizeof(struct Syntax));
+ mutt_mem_realloc(&(line_info[n].syntax), sizeof(struct Syntax));
}
line_info[i++].type = MT_COLOR_SIGNATURE;
}
break;
}
if (++(line_info[n].chunks) > 1)
- safe_realloc(&(line_info[n].syntax),
- (line_info[n].chunks) * sizeof(struct Syntax));
+ mutt_mem_realloc(&(line_info[n].syntax),
+ (line_info[n].chunks) * sizeof(struct Syntax));
}
i = line_info[n].chunks - 1;
pmatch[0].rm_so += offset;
if (!found)
{
if (++(line_info[n].chunks) > 1)
- safe_realloc(&(line_info[n].syntax),
- (line_info[n].chunks) * sizeof(struct Syntax));
+ mutt_mem_realloc(&(line_info[n].syntax),
+ (line_info[n].chunks) * sizeof(struct Syntax));
}
i = line_info[n].chunks - 1;
pmatch[0].rm_so += offset;
b_read = (int) (*last_pos - offset);
*buf_ready = 1;
- safe_realloc(fmt, *blen);
+ mutt_mem_realloc(fmt, *blen);
/* incomplete mbyte characters trigger a segfault in regex processing for
* certain versions of glibc. Trim them if necessary. */
if (*last == *max)
{
- safe_realloc(line_info, sizeof(struct Line) * (*max += LINES));
+ mutt_mem_realloc(line_info, sizeof(struct Line) * (*max += LINES));
for (ch = *last; ch < *max; ch++)
{
memset(&((*line_info)[ch]), 0, sizeof(struct Line));
(*line_info)[ch].type = -1;
(*line_info)[ch].search_cnt = -1;
- (*line_info)[ch].syntax = safe_malloc(sizeof(struct Syntax));
+ (*line_info)[ch].syntax = mutt_mem_malloc(sizeof(struct Syntax));
((*line_info)[ch].syntax)[0].first = ((*line_info)[ch].syntax)[0].last = -1;
}
}
(offset ? REG_NOTBOL : 0)) == 0)
{
if (++((*line_info)[n].search_cnt) > 1)
- safe_realloc(&((*line_info)[n].search),
- ((*line_info)[n].search_cnt) * sizeof(struct Syntax));
+ mutt_mem_realloc(&((*line_info)[n].search),
+ ((*line_info)[n].search_cnt) * sizeof(struct Syntax));
else
- (*line_info)[n].search = safe_malloc(sizeof(struct Syntax));
+ (*line_info)[n].search = mutt_mem_malloc(sizeof(struct Syntax));
pmatch[0].rm_so += offset;
pmatch[0].rm_eo += offset;
((*line_info)[n].search)[(*line_info)[n].search_cnt - 1].first = pmatch[0].rm_so;
rd->line_info[i].search_cnt = -1;
rd->line_info[i].quote = NULL;
- safe_realloc(&(rd->line_info[i].syntax), sizeof(struct Syntax));
+ mutt_mem_realloc(&(rd->line_info[i].syntax), sizeof(struct Syntax));
if (rd->search_compiled && rd->line_info[i].search)
FREE(&(rd->line_info[i].search));
}
}
rd.max_line = LINES; /* number of lines on screen, from curses */
- rd.line_info = safe_calloc(rd.max_line, sizeof(struct Line));
+ rd.line_info = mutt_mem_calloc(rd.max_line, sizeof(struct Line));
for (i = 0; i < rd.max_line; i++)
{
rd.line_info[i].type = -1;
rd.line_info[i].search_cnt = -1;
- rd.line_info[i].syntax = safe_malloc(sizeof(struct Syntax));
+ rd.line_info[i].syntax = mutt_mem_malloc(sizeof(struct Syntax));
(rd.line_info[i].syntax)[0].first = (rd.line_info[i].syntax)[0].last = -1;
}
snprintf(helpstr, sizeof(helpstr), "%s %s", tmphelp, buffer);
}
- rd.index_status_window = safe_calloc(1, sizeof(struct MuttWindow));
- rd.index_window = safe_calloc(1, sizeof(struct MuttWindow));
- rd.pager_status_window = safe_calloc(1, sizeof(struct MuttWindow));
- rd.pager_window = safe_calloc(1, sizeof(struct MuttWindow));
+ rd.index_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+ rd.index_window = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+ rd.pager_status_window = mutt_mem_calloc(1, sizeof(struct MuttWindow));
+ rd.pager_window = mutt_mem_calloc(1, sizeof(struct MuttWindow));
pager_menu = mutt_new_menu(MENU_PAGER);
pager_menu->custom_menu_redraw = pager_menu_redraw;
if (!rd.line_info[i].continuation)
rd.lines++;
- Resize = safe_malloc(sizeof(struct Resize));
+ Resize = mutt_mem_malloc(sizeof(struct Resize));
Resize->line = rd.lines;
Resize->search_compiled = rd.search_compiled;
*/
static inline struct Parameter *mutt_new_parameter(void)
{
- return safe_calloc(1, sizeof(struct Parameter));
+ return mutt_mem_calloc(1, sizeof(struct Parameter));
}
void mutt_delete_parameter(const char *attribute, struct Parameter **p);
{
/* grow the buffer */
*linelen += STRING;
- safe_realloc(&line, *linelen);
+ mutt_mem_realloc(&line, *linelen);
buf = line + offset;
}
}
{
struct Body *p = mutt_new_body();
char *c = NULL;
- char *line = safe_malloc(LONG_STRING);
+ char *line = mutt_mem_malloc(LONG_STRING);
size_t linelen = LONG_STRING;
p->hdr_offset = ftello(fp);
if (*p == '>')
{
size_t olen = onull - o, slen = p - s + 1;
- ret = safe_malloc(olen + slen + 1);
+ ret = mutt_mem_malloc(olen + slen + 1);
if (o)
memcpy(ret, o, olen);
memcpy(ret + olen, s, slen);
short user_hdrs, short weed)
{
struct Envelope *e = mutt_new_envelope();
- char *line = safe_malloc(LONG_STRING);
+ char *line = mutt_mem_malloc(LONG_STRING);
char *p = NULL;
LOFF_T loc;
size_t linelen = LONG_STRING;
}
else
{
- pat->p.regex = safe_malloc(sizeof(regex_t));
+ pat->p.regex = mutt_mem_malloc(sizeof(regex_t));
r = REGCOMP(pat->p.regex, buf.data,
REG_NEWLINE | REG_NOSUB | mutt_which_case(buf.data));
if (r != 0)
}
blen = STRING;
- buf = safe_malloc(blen);
+ buf = mutt_mem_malloc(blen);
/* search the file "fp" */
while (lng > 0)
mutt_buffer_init(&err);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
pat = mutt_pattern_comp(buf, MUTT_FULL_MSG, &err);
if (!pat)
{
mutt_message(_("Compiling search pattern..."));
mutt_pattern_free(&SearchPattern);
err.dsize = STRING;
- err.data = safe_malloc(err.dsize);
+ err.data = mutt_mem_malloc(err.dsize);
SearchPattern = mutt_pattern_comp(temp, MUTT_FULL_MSG, &err);
if (!SearchPattern)
{
static inline struct Pattern *new_pattern(void)
{
- return safe_calloc(1, sizeof(struct Pattern));
+ return mutt_mem_calloc(1, sizeof(struct Pattern));
}
int mutt_pattern_exec(struct Pattern *pat, enum PatternExecFlag flags,
{
char *fingerprint = NULL, *pf = NULL;
- pf = fingerprint = safe_malloc((length * 2) + 1);
+ pf = fingerprint = mutt_mem_malloc((length * 2) + 1);
for (int i = 0; i < length; i++)
{
{
if (lsig)
{
- struct PgpSignature *signature = safe_calloc(1, sizeof(struct PgpSignature));
+ struct PgpSignature *signature =
+ mutt_mem_calloc(1, sizeof(struct PgpSignature));
*lsig = signature;
lsig = &signature->next;
if (!addr)
break;
- chr = safe_malloc(l);
+ chr = mutt_mem_malloc(l);
if (l > 0)
{
memcpy(chr, buff + 1, l - 1);
chr[l - 1] = '\0';
}
- *addr = uid = safe_calloc(1, sizeof(struct PgpUid)); /* XXX */
+ *addr = uid = mutt_mem_calloc(1, sizeof(struct PgpUid)); /* XXX */
uid->addr = chr;
uid->parent = p;
uid->trust = 0;
size_t error_buf_len;
error_buf_len = sizeof("fopen: ") - 1 + strlen(ringfile) + 1;
- error_buf = safe_malloc(error_buf_len);
+ error_buf = mutt_mem_malloc(error_buf_len);
snprintf(error_buf, error_buf_len, "fopen: %s", ringfile);
perror(error_buf);
FREE(&error_buf);
}
else if (pt == PT_NAME)
{
- char *tmp = safe_malloc(l);
+ char *tmp = mutt_mem_malloc(l);
memcpy(tmp, buff + 1, l - 1);
tmp[l - 1] = '\0';
ctx->path = safe_strdup(buf);
ctx->realpath = safe_strdup(ctx->path);
- pop_data = safe_calloc(1, sizeof(struct PopData));
+ pop_data = mutt_mem_calloc(1, sizeof(struct PopData));
pop_data->conn = conn;
ctx->data = pop_data;
return;
}
- url = p = safe_calloc(strlen(PopHost) + 7, sizeof(char));
+ url = p = mutt_mem_calloc(strlen(PopHost) + 7, sizeof(char));
if (url_check_scheme(PopHost) == U_UNKNOWN)
{
strcpy(url, "pop://");
if (!conn)
return;
- pop_data = safe_calloc(1, sizeof(struct PopData));
+ pop_data = mutt_mem_calloc(1, sizeof(struct PopData));
pop_data->conn = conn;
if (pop_open_connection(pop_data) < 0)
mutt_message(_("Authenticating (SASL)..."));
bufsize = ((olen * 2) > LONG_STRING) ? (olen * 2) : LONG_STRING;
- buf = safe_malloc(bufsize);
+ buf = mutt_mem_malloc(bufsize);
snprintf(buf, bufsize, "AUTH %s", mech);
olen = strlen(buf);
if ((olen * 2) > bufsize)
{
bufsize = olen * 2;
- safe_realloc(&buf, bufsize);
+ mutt_mem_realloc(&buf, bufsize);
}
if (sasl_encode64(pc, olen, buf, bufsize, &olen) != SASL_OK)
{
if (!pop_data->auth_list)
{
- pop_data->auth_list = safe_malloc(strlen(line) + 1);
+ pop_data->auth_list = mutt_mem_malloc(strlen(line) + 1);
*pop_data->auth_list = '\0';
}
else
{
- safe_realloc(&pop_data->auth_list, strlen(pop_data->auth_list) + strlen(line) + 2);
+ mutt_mem_realloc(&pop_data->auth_list, strlen(pop_data->auth_list) + strlen(line) + 2);
strcat(pop_data->auth_list, " ");
}
strcat(pop_data->auth_list, line);
if (ret < 0)
return ret;
- inbuf = safe_malloc(sizeof(buf));
+ inbuf = mutt_mem_malloc(sizeof(buf));
while (true)
{
lenbuf = 0;
}
- safe_realloc(&inbuf, lenbuf + sizeof(buf));
+ mutt_mem_realloc(&inbuf, lenbuf + sizeof(buf));
}
FREE(&inbuf);
{
if (!first)
{
- first = safe_calloc(1, sizeof(struct Query));
+ first = mutt_mem_calloc(1, sizeof(struct Query));
cur = first;
}
else
{
- cur->next = safe_calloc(1, sizeof(struct Query));
+ cur->next = mutt_mem_calloc(1, sizeof(struct Query));
cur = cur->next;
}
for (queryp = results; queryp; queryp = queryp->next)
menu->max++;
- menu->data = QueryTable = safe_calloc(menu->max, sizeof(struct Entry));
+ menu->data = QueryTable = mutt_mem_calloc(menu->max, sizeof(struct Entry));
for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
QueryTable[i].data = queryp;
if (op == OP_QUERY)
{
- menu->data = QueryTable = safe_calloc(menu->max, sizeof(struct Entry));
+ menu->data = QueryTable =
+ mutt_mem_calloc(menu->max, sizeof(struct Entry));
for (i = 0, queryp = results; queryp; queryp = queryp->next, i++)
QueryTable[i].data = queryp;
bool clear = false;
/* append */
- safe_realloc(&QueryTable, menu->max * sizeof(struct Entry));
+ mutt_mem_realloc(&QueryTable, menu->max * sizeof(struct Entry));
menu->data = QueryTable;
}
else
{
- new = (struct AttachPtr *) safe_calloc(1, sizeof(struct AttachPtr));
+ new = (struct AttachPtr *) mutt_mem_calloc(1, sizeof(struct AttachPtr));
mutt_actx_add_attach(actx, new);
new->content = m;
menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_ATTACH, AttachHelp);
mutt_push_current_menu(menu);
- actx = safe_calloc(sizeof(struct AttachCtx), 1);
+ actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1);
actx->hdr = hdr;
actx->root_fp = msg->fp;
mutt_update_recvattach_menu(actx, menu, 1);
if (*used == *slots)
{
*slots += 5;
- safe_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
+ mutt_mem_realloc(type2_list, sizeof(struct Remailer *) * (*slots));
}
(*type2_list)[(*used)++] = entry;
static struct Remailer *mix_new_remailer(void)
{
- return safe_calloc(1, sizeof(struct Remailer));
+ return mutt_mem_calloc(1, sizeof(struct Remailer));
}
static void mix_free_remailer(struct Remailer **r)
if (!chain->cl)
return;
- safe_realloc(coordsp, sizeof(struct Coord) * chain->cl);
+ mutt_mem_realloc(coordsp, sizeof(struct Coord) * chain->cl);
coords = *coordsp;
return;
}
- chain = safe_calloc(1, sizeof(struct MixChain));
+ chain = mutt_mem_calloc(1, sizeof(struct MixChain));
struct ListNode *p;
STAILQ_FOREACH(p, chainhead, entries)
if (get_field_text(field + 4, &test_command, type, filename, line) && test_command)
{
len = mutt_strlen(test_command) + STRING;
- safe_realloc(&test_command, len);
+ mutt_mem_realloc(&test_command, len);
rfc1524_expand_command(a, a->filename, type, test_command, len);
if (mutt_system(test_command) != 0)
{
*/
struct Rfc1524MailcapEntry *rfc1524_new_entry(void)
{
- return safe_calloc(1, sizeof(struct Rfc1524MailcapEntry));
+ return mutt_mem_calloc(1, sizeof(struct Rfc1524MailcapEntry));
}
/**
if (cd == (iconv_t)(-1))
return (size_t)(-1);
obl = 4 * flen + 1;
- ob = buf = safe_malloc(obl);
+ ob = buf = mutt_mem_malloc(obl);
n = iconv(cd, &f, &flen, &ob, &obl);
if (n == (size_t)(-1) || iconv(cd, 0, 0, &ob, &obl) == (size_t)(-1))
{
*tlen = ob - buf;
- safe_realloc(&buf, ob - buf + 1);
+ mutt_mem_realloc(&buf, ob - buf + 1);
*t = buf;
iconv_close(cd);
n = c1 ? c1 - c : mutt_strlen(c);
if (!n)
return 0;
- fromcode = safe_malloc(n + 1);
+ fromcode = mutt_mem_malloc(n + 1);
strfcpy(fromcode, c, n + 1);
m = convert_string(u, ulen, fromcode, Charset, &s, &slen);
FREE(&fromcode);
if (!n)
continue;
- t = safe_malloc(n + 1);
+ t = mutt_mem_malloc(n + 1);
memcpy(t, p, n);
t[n] = '\0';
{
ret = 1;
icode = 0;
- safe_realloc(&u, (ulen = dlen) + 1);
+ mutt_mem_realloc(&u, (ulen = dlen) + 1);
memcpy(u, d, dlen);
u[ulen] = 0;
}
/* Initialise the output buffer with the us-ascii prefix. */
buflen = 2 * ulen;
- buf = safe_malloc(buflen);
+ buf = mutt_mem_malloc(buflen);
bufpos = t0 - u;
memcpy(buf, u, t0 - u);
if ((bufpos + wlen + lb_len) > buflen)
{
buflen = bufpos + wlen + lb_len;
- safe_realloc(&buf, buflen);
+ mutt_mem_realloc(&buf, buflen);
}
r = encode_block(buf + bufpos, t, n, icode, tocode, encoder);
assert(r == wlen);
/* Add last encoded word and us-ascii suffix to buffer. */
buflen = bufpos + wlen + (u + ulen - t1);
- safe_realloc(&buf, buflen + 1);
+ mutt_mem_realloc(&buf, buflen + 1);
r = encode_block(buf + bufpos, t, t1 - t, icode, tocode, encoder);
assert(r == wlen);
bufpos += wlen;
char *charset = NULL;
int rv = -1;
- pd = d0 = safe_malloc(strlen(s) + 1);
+ pd = d0 = mutt_mem_malloc(strlen(s) + 1);
for (pp = s; (pp1 = strchr(pp, '?')); pp = pp1 + 1)
{
return;
dlen = 4 * strlen(s); /* should be enough */
- d = d0 = safe_malloc(dlen + 1);
+ d = d0 = mutt_mem_malloc(dlen + 1);
while (*s && dlen > 0)
{
size_t tlen;
n = mutt_strlen(s);
- t = safe_malloc(n + 1);
+ t = mutt_mem_malloc(n + 1);
strfcpy(t, s, n + 1);
convert_nonmime_string(&t);
tlen = mutt_strlen(t);
static struct Rfc2231Parameter *rfc2231_new_parameter(void)
{
- return safe_calloc(1, sizeof(struct Rfc2231Parameter));
+ return mutt_mem_calloc(1, sizeof(struct Rfc2231Parameter));
}
/**
vl = strlen(par->value);
- safe_realloc(&value, l + vl + 1);
+ mutt_mem_realloc(&value, l + vl + 1);
strcpy(value + l, par->value);
l += vl;
if (encode)
{
- e = safe_malloc(dlen + 2 * ext + strlen(charset) + 3);
+ e = mutt_mem_malloc(dlen + 2 * ext + strlen(charset) + 3);
sprintf(e, "%s''", charset);
t = e + strlen(e);
for (s = d, slen = dlen; slen; s++, slen--)
for (; addr; addr = addr->next)
if (!addr->group && addr->mailbox && strchr(addr->mailbox, '@') == NULL)
{
- p = safe_malloc(mutt_strlen(addr->mailbox) + mutt_strlen(host) + 2);
+ p = mutt_mem_malloc(mutt_strlen(addr->mailbox) + mutt_strlen(host) + 2);
sprintf(p, "%s@%s", addr->mailbox, host);
FREE(&addr->mailbox);
addr->mailbox = p;
*/
static inline struct Address *rfc822_new_address(void)
{
- return safe_calloc(1, sizeof(struct Address));
+ return mutt_mem_calloc(1, sizeof(struct Address));
}
#endif /* _MUTT_RFC822_H */
int rlen = STRING;
int n;
- *strp = safe_malloc(rlen);
+ *strp = mutt_mem_malloc(rlen);
for (;;)
{
va_list ap;
if (n == 0) /* convention is to use NULL for zero-length strings. */
FREE(strp);
else if (n != rlen - 1)
- safe_realloc(strp, n + 1);
+ mutt_mem_realloc(strp, n + 1);
return n;
}
/* increase size and try again */
rlen = n + 1;
- safe_realloc(strp, rlen);
+ mutt_mem_realloc(strp, rlen);
}
/* not reached */
}
FREE(&pattern);
return -1;
}
- ptr = safe_calloc(1, sizeof(struct Score));
+ ptr = mutt_mem_calloc(1, sizeof(struct Score));
if (last)
last->next = ptr;
else
if (curenv->real_subj)
{
FREE(&env->subject);
- env->subject = safe_malloc(mutt_strlen(curenv->real_subj) + 5);
+ env->subject = mutt_mem_malloc(mutt_strlen(curenv->real_subj) + 5);
sprintf(env->subject, "Re: %s", curenv->real_subj);
}
else if (!env->subject)
else if (option(OPT_USE_DOMAIN))
{
adr = rfc822_new_address();
- adr->mailbox = safe_malloc(mutt_strlen(Username) + mutt_strlen(fqdn) + 2);
+ adr->mailbox = mutt_mem_malloc(mutt_strlen(Username) + mutt_strlen(fqdn) + 2);
sprintf(adr->mailbox, "%s@%s", NONULL(Username), NONULL(fqdn));
}
else
if (!attf)
return 0;
- char *inputline = safe_malloc(LONG_STRING);
+ char *inputline = mutt_mem_malloc(LONG_STRING);
int found = 0;
while (!feof(attf))
{
if (cd1 == (iconv_t)(-1))
return -1;
- cd = safe_calloc(ncodes, sizeof(iconv_t));
- score = safe_calloc(ncodes, sizeof(size_t));
- states = safe_calloc(ncodes, sizeof(struct ContentState));
- infos = safe_calloc(ncodes, sizeof(struct Content));
+ cd = mutt_mem_calloc(ncodes, sizeof(iconv_t));
+ score = mutt_mem_calloc(ncodes, sizeof(size_t));
+ states = mutt_mem_calloc(ncodes, sizeof(struct ContentState));
+ infos = mutt_mem_calloc(ncodes, sizeof(struct Content));
for (int i = 0; i < ncodes; i++)
{
}
/* Copy them */
- tcode = safe_malloc(ncodes * sizeof(char *));
+ tcode = mutt_mem_malloc(ncodes * sizeof(char *));
for (c = tocodes, i = 0; c; c = c1 ? c1 + 1 : 0, i++)
{
c1 = strchr(c, ':');
return NULL;
}
- info = safe_calloc(1, sizeof(struct Content));
+ info = mutt_mem_calloc(1, sizeof(struct Content));
memset(&state, 0, sizeof(state));
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
break;
}
- struct ListNode **ref = safe_calloc(length, sizeof(struct ListNode *));
+ struct ListNode **ref = mutt_mem_calloc(length, sizeof(struct ListNode *));
// store in reverse order
size_t tmp = length;
continue;
rfc2047_encode_string32(&tmp);
- safe_realloc(&np->data, mutt_strlen(np->data) + 2 + mutt_strlen(tmp) + 1);
+ mutt_mem_realloc(&np->data, mutt_strlen(np->data) + 2 + mutt_strlen(tmp) + 1);
sprintf(np->data + i, ": %s", NONULL(tmp));
if (addr->mailbox && !addr->group)
{
if (*argslen == *argsmax)
- safe_realloc(&args, (*argsmax += 5) * sizeof(char *));
+ mutt_mem_realloc(&args, (*argsmax += 5) * sizeof(char *));
args[(*argslen)++] = addr->mailbox;
}
}
static char **add_option(char **args, size_t *argslen, size_t *argsmax, char *s)
{
if (*argslen == *argsmax)
- safe_realloc(&args, (*argsmax += 5) * sizeof(char *));
+ mutt_mem_realloc(&args, (*argsmax += 5) * sizeof(char *));
args[(*argslen)++] = s;
return args;
}
while ((ps = strtok(ps, " ")))
{
if (argslen == argsmax)
- safe_realloc(&args, sizeof(char *) * (argsmax += 5));
+ mutt_mem_realloc(&args, sizeof(char *) * (argsmax += 5));
if (i)
{
while ((ps = strtok(ps, " ")))
{
if (extra_argslen == extra_argsmax)
- safe_realloc(&extra_args, sizeof(char *) * (extra_argsmax += 5));
+ mutt_mem_realloc(&extra_args, sizeof(char *) * (extra_argsmax += 5));
extra_args[extra_argslen++] = ps;
ps = NULL;
#endif
if (argslen == argsmax)
- safe_realloc(&args, sizeof(char *) * (++argsmax));
+ mutt_mem_realloc(&args, sizeof(char *) * (++argsmax));
args[argslen++] = NULL;
tmp_folder_name += lastsep; /* basename */
int sfn_len = mutt_strlen(tmp_folder_name) +
sidebar_folder_depth * mutt_strlen(SidebarIndentString) + 1;
- sidebar_folder_name = safe_malloc(sfn_len);
+ sidebar_folder_name = mutt_mem_malloc(sfn_len);
sidebar_folder_name[0] = 0;
for (int i = 0; i < sidebar_folder_depth; i++)
safe_strcat(sidebar_folder_name, sfn_len, NONULL(SidebarIndentString));
if (EntryCount >= EntryLen)
{
EntryLen += 10;
- safe_realloc(&Entries, EntryLen * sizeof(struct SbEntry *));
+ mutt_mem_realloc(&Entries, EntryLen * sizeof(struct SbEntry *));
}
- Entries[EntryCount] = safe_calloc(1, sizeof(struct SbEntry));
+ Entries[EntryCount] = mutt_mem_calloc(1, sizeof(struct SbEntry));
Entries[EntryCount]->buffy = b;
if (TopIndex < 0)
mutt_message(_("Authenticating (%s)..."), mech);
bufsize = ((len * 2) > LONG_STRING) ? (len * 2) : LONG_STRING;
- buf = safe_malloc(bufsize);
+ buf = mutt_mem_malloc(bufsize);
snprintf(buf, bufsize, "AUTH %s", mech);
if (len)
if ((len * 2) > bufsize)
{
bufsize = len * 2;
- safe_realloc(&buf, bufsize);
+ mutt_mem_realloc(&buf, bufsize);
}
if (sasl_encode64(data, len, buf, bufsize, &len) != SASL_OK)
{
* From now on we can simply ignore invisible subtrees
*/
calculate_visibility(ctx, &max_depth);
- pfx = safe_malloc(width * max_depth + 2);
- arrow = safe_malloc(width * max_depth + 2);
+ pfx = mutt_mem_malloc(width * max_depth + 2);
+ arrow = mutt_mem_malloc(width * max_depth + 2);
while (tree)
{
if (depth)
{
myarrow[width] = MUTT_TREE_RARROW;
myarrow[width + 1] = 0;
- new_tree = safe_malloc((2 + depth * width));
+ new_tree = mutt_mem_malloc((2 + depth * width));
if (start_depth > 1)
{
strncpy(new_tree, pfx, (start_depth - 1) * width);
top = thread;
- array = safe_calloc((array_size = 256), sizeof(struct MuttThread *));
+ array = mutt_mem_calloc((array_size = 256), sizeof(struct MuttThread *));
while (true)
{
if (init || !thread->sort_key)
for (i = 0; thread; i++, thread = thread->prev)
{
if (i >= array_size)
- safe_realloc(&array, (array_size *= 2) * sizeof(struct MuttThread *));
+ mutt_mem_realloc(&array, (array_size *= 2) * sizeof(struct MuttThread *));
array[i] = thread;
}
{
new = (option(OPT_DUPLICATE_THREADS) ? thread : NULL);
- thread = safe_calloc(1, sizeof(struct MuttThread));
+ thread = mutt_mem_calloc(1, sizeof(struct MuttThread));
thread->message = cur;
thread->check_subject = true;
cur->thread = thread;
new = mutt_hash_find(ctx->thread_hash, ref->data);
if (!new)
{
- new = safe_calloc(1, sizeof(struct MuttThread));
+ new = mutt_mem_calloc(1, sizeof(struct MuttThread));
mutt_hash_insert(ctx->thread_hash, ref->data, new);
}
else
while (src && *src)
{
- qs = safe_calloc(1, sizeof(struct UrlQueryString));
+ qs = mutt_mem_calloc(1, sizeof(struct UrlQueryString));
if ((k = strchr(src, '&')))
*k = '\0';