From 617e7d83d14e14e6a520a48e75437211b16c8834 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 29 Oct 2006 02:09:23 +0100 Subject: [PATCH] exit mem_realloc, enters p_realloc/xrealloc. Signed-off-by: Pierre Habouzit --- account.c | 1 - alias.c | 3 +-- attach.c | 1 - browser.c | 15 ++++------- buffer.c | 5 ++-- buffy.c | 1 - charset.c | 3 +-- color.c | 3 +-- commands.c | 1 - compose.c | 12 +++------ compress.c | 1 - copy.c | 19 +++++--------- crypt-gpgme.c | 9 +++---- crypt-mod.c | 1 - crypt.c | 5 ++-- curs_lib.c | 3 +-- curs_main.c | 1 - edit.c | 11 ++++---- enter.c | 11 ++++---- from.c | 1 - gnupgparse.c | 1 - handler.c | 9 +++---- hash.c | 2 -- hcache.c | 3 +-- history.c | 1 - hook.c | 1 - imap/auth.c | 1 - imap/auth_sasl.c | 1 - imap/browse.c | 9 +++---- imap/command.c | 5 ++-- imap/imap.c | 1 - imap/message.c | 1 - imap/mx_imap.c | 1 - imap/utf7.c | 6 ++--- imap/util.c | 1 - init.c | 1 - keymap.c | 1 - lib-lib/mem.h | 67 +++++++++++++++++++++++++---------------------- lib.c | 3 +-- lib/Makefile.am | 4 +-- lib/list.c | 11 ++++---- lib/mem.c | 36 ------------------------- lib/mem.h | 14 ---------- lib/rx.c | 1 - lib/str.c | 4 +-- list.c | 1 - main.c | 1 - mbox.c | 1 - menu.c | 1 - mh.c | 3 +-- mutt_idna.c | 7 +++-- mutt_libesmtp.c | 1 - mutt_sasl.c | 1 - mutt_socket.c | 1 - mutt_ssl.c | 1 - mutt_ssl_gnutls.c | 1 - mutt_tunnel.c | 1 - muttlib.c | 3 +-- mx.c | 5 ++-- nntp/mx_nntp.c | 1 - nntp/newsrc.c | 9 +++---- nntp/nntp.c | 5 ++-- pager.c | 16 +++++------ parse.c | 3 +-- pattern.c | 1 - pgp.c | 3 +-- pgpinvoke.c | 1 - pgpkey.c | 3 +-- pgplib.c | 2 -- pgppacket.c | 2 -- pgppubring.c | 1 - pop/mx_pop.c | 1 - pop/pop.c | 1 - pop/pop_auth.c | 1 - pop/pop_lib.c | 9 +++---- postpone.c | 1 - query.c | 3 +-- recvattach.c | 3 +-- recvcmd.c | 1 - remailer.c | 5 ++-- rfc1524.c | 3 +-- rfc2047.c | 7 +++-- rfc2231.c | 4 +-- rfc3676.c | 3 +-- rfc822.c | 1 - score.c | 1 - send.c | 1 - sendlib.c | 18 ++++++------- sidebar.c | 1 - smime.c | 3 +-- status.c | 1 - thread.c | 3 +-- url.c | 2 -- 93 files changed, 140 insertions(+), 300 deletions(-) delete mode 100644 lib/mem.c delete mode 100644 lib/mem.h diff --git a/account.c b/account.c index 0e0f946..406d492 100644 --- a/account.c +++ b/account.c @@ -21,7 +21,6 @@ #include "account.h" #include "url.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/alias.c b/alias.c index f5b6859..48e76c5 100644 --- a/alias.c +++ b/alias.c @@ -16,7 +16,6 @@ #include -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" @@ -668,7 +667,7 @@ new_aliases: menu->max++; } - mem_realloc (&AliasTable, menu->max * sizeof (ALIAS *)); + p_realloc(&AliasTable, menu->max); menu->data = AliasTable; for (i = omax, aliasp = aliases; aliasp; aliasp = aliasp->next, i++) { diff --git a/attach.c b/attach.c index 42953e3..dfdab79 100644 --- a/attach.c +++ b/attach.c @@ -28,7 +28,6 @@ #include "mx.h" #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/browser.c b/browser.c index 5baa3b7..6a9e6ec 100644 --- a/browser.c +++ b/browser.c @@ -33,7 +33,6 @@ #endif #include "sidebar.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/list.h" @@ -429,21 +428,17 @@ static void add_folder (MUTTMENU * m, struct browser_state *state, { if (state->entrylen == state->entrymax) { /* need to allocate more space */ - mem_realloc (&state->entry, - sizeof (struct folder_file) * (state->entrymax += 256)); - memset (&state->entry[state->entrylen], 0, - sizeof (struct folder_file) * 256); + p_realloc(&state->entry, state->entrymax += 256); + p_clear(&state->entry[state->entrylen], 256); if (m) m->data = state->entry; } if (s != NULL) { - (state->entry)[state->entrylen].mode = s->st_mode; + (state->entry)[state->entrylen].mode = s->st_mode; (state->entry)[state->entrylen].mtime = s->st_mtime; - (state->entry)[state->entrylen].size = s->st_size; - - (state->entry)[state->entrylen].st = p_new(struct stat, 1); - memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat)); + (state->entry)[state->entrylen].size = s->st_size; + (state->entry)[state->entrylen].st = p_dup(s, 1); } (state->entry)[state->entrylen].new = new; diff --git a/buffer.c b/buffer.c index cfe19be..bfa0dd8 100644 --- a/buffer.c +++ b/buffer.c @@ -18,7 +18,6 @@ #include "buffer.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/debug.h" @@ -86,14 +85,14 @@ void mutt_buffer_free (BUFFER ** p) /* dynamically grows a BUFFER to accomodate s, in increments of 128 bytes. * Always one byte bigger than necessary for the null terminator, and * the buffer is always null-terminated */ -void mutt_buffer_add (BUFFER * buf, const char *s, size_t len) +void mutt_buffer_add (BUFFER *buf, const char *s, size_t len) { size_t offset; if (buf->dptr + len + 1 > buf->data + buf->dsize) { offset = buf->dptr - buf->data; buf->dsize += len < 128 ? 128 : len + 1; - mem_realloc ((void **) &buf->data, buf->dsize); + p_realloc(&buf->data, buf->dsize); buf->dptr = buf->data + offset; } memcpy (buf->dptr, s, len); diff --git a/buffy.c b/buffy.c index 7688aa4..da37268 100644 --- a/buffy.c +++ b/buffy.c @@ -29,7 +29,6 @@ #include "imap.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include diff --git a/charset.c b/charset.c index 9bf63f8..8f5bb08 100644 --- a/charset.c +++ b/charset.c @@ -28,7 +28,6 @@ #include "charset.h" #include "ascii.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" @@ -577,7 +576,7 @@ static size_t convert_string (const char *f, size_t flen, *tlen = ob - buf; - mem_realloc (&buf, ob - buf + 1); + p_realloc(&buf, ob - buf + 1); *t = buf; iconv_close (cd); diff --git a/color.c b/color.c index 854dde5..1c60c77 100644 --- a/color.c +++ b/color.c @@ -19,7 +19,6 @@ #include "mutt_curses.h" #include "mapping.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -702,7 +701,7 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, } else if (object == MT_COLOR_QUOTED) { if (q_level >= ColorQuoteSize) { - mem_realloc (&ColorQuote, (ColorQuoteSize += 2) * sizeof (int)); + p_realloc(&ColorQuote, ColorQuoteSize += 2); ColorQuote[ColorQuoteSize - 2] = ColorDefs[MT_COLOR_QUOTED]; ColorQuote[ColorQuoteSize - 1] = ColorDefs[MT_COLOR_QUOTED]; } diff --git a/commands.c b/commands.c index 9b00f9e..a6a92e8 100644 --- a/commands.c +++ b/commands.c @@ -40,7 +40,6 @@ #include "buffy.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/compose.c b/compose.c index 8c0006a..b46050e 100644 --- a/compose.c +++ b/compose.c @@ -41,7 +41,6 @@ #include "nntp.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" @@ -751,7 +750,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ if (!(WithCrypto & APPLICATION_PGP)) break; if (idxlen == idxmax) { - mem_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); + p_realloc(&idx, idxmax += 5); menu->data = idx; } @@ -791,8 +790,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ break; if (idxlen + numfiles >= idxmax) { - mem_realloc (&idx, - sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles)); + p_realloc(&idx, idxmax += 5 + numfiles); menu->data = idx; } @@ -919,9 +917,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ } if (idxlen + Context->tagged >= idxmax) { - mem_realloc (&idx, - sizeof (ATTACHPTR *) * (idxmax += - 5 + Context->tagged)); + p_realloc(&idx, idxmax += 5 + Context->tagged); menu->data = idx; } @@ -1193,7 +1189,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ continue; } if (idxlen == idxmax) { - mem_realloc (&idx, sizeof (ATTACHPTR *) * (idxmax += 5)); + p_realloc(&idx, idxmax += 5); menu->data = idx; } diff --git a/compress.c b/compress.c index 47f50c5..b9e50ed 100644 --- a/compress.c +++ b/compress.c @@ -17,7 +17,6 @@ #include "mbox.h" #include "mutt_curses.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/copy.c b/copy.c index 19b3d8c..05768a3 100644 --- a/copy.c +++ b/copy.c @@ -23,7 +23,6 @@ #include "mutt_crypt.h" #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/debug.h" @@ -156,9 +155,8 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, if (!headers[x]) headers[x] = this_one; else { - mem_realloc (&headers[x], str_len (headers[x]) + - str_len (this_one) + sizeof (char)); - strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */ + p_realloc(&headers[x], str_len(headers[x]) + str_len(this_one) + 1); + strcat(headers[x], this_one); /* __STRCAT_CHECKED__ */ p_delete(&this_one); } @@ -226,14 +224,12 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, * abbreviations (curline is 0), $max_display_recips is 0 and * while the number hasn't reached $max_display_recips yet */ else if (curline == 0 || MaxDispRecips == 0 || ++curline <= MaxDispRecips) { - mem_realloc (&this_one, - str_len (this_one) + str_len (buf) + - sizeof (char)); + p_realloc(&this_one, str_len(this_one) + str_len(buf) + 1); strcat (this_one, buf); /* __STRCAT_CHECKED__ */ /* only for the first line which doesn't exeeds * $max_display_recips: abbreviate it */ } else if (curline == MaxDispRecips+1) { - mem_realloc (&this_one, str_len (this_one) + 5); + p_realloc(&this_one, str_len(this_one) + 5); strcat (this_one, " ..."); } } @@ -249,8 +245,7 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, if (!headers[x]) headers[x] = this_one; else { - mem_realloc (&headers[x], str_len (headers[x]) + - str_len (this_one) + sizeof (char)); + p_realloc(&headers[x], str_len(headers[x]) + str_len(this_one) + 1); strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */ p_delete(&this_one); } @@ -827,7 +822,7 @@ static void format_address_header (char **h, ADDRESS * a) buflen = linelen + 3; - mem_realloc (h, buflen); + p_realloc(h, buflen); for (count = 0; a; a = a->next, count++) { ADDRESS *tmp = a->next; @@ -855,7 +850,7 @@ static void format_address_header (char **h, ADDRESS * a) } buflen += l + str_len (cbuf) + str_len (c2buf); - mem_realloc (h, buflen); + p_realloc(h, buflen); strcat (*h, cbuf); /* __STRCAT_CHECKED__ */ strcat (*h, buf); /* __STRCAT_CHECKED__ */ strcat (*h, c2buf); /* __STRCAT_CHECKED__ */ diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 0c0bbf7..8bb7866 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -33,7 +33,6 @@ #include "recvattach.h" #include "sort.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -554,7 +553,7 @@ static gpgme_key_t *create_recipient_set (const char *keylist, err = gpgme_get_key (context, buf, &key, 0); if (!err) { - mem_realloc (&rset, sizeof (*rset) * (rset_n + 1)); + p_realloc(&rset, rset_n + 1); rset[rset_n++] = key; } else { @@ -568,7 +567,7 @@ static gpgme_key_t *create_recipient_set (const char *keylist, } /* NULL terminate. */ - mem_realloc (&rset, sizeof (*rset) * (rset_n + 1)); + p_realloc(&rset, rset_n + 1); rset[rset_n++] = NULL; if (context) @@ -3259,7 +3258,7 @@ static crypt_key_t *crypt_select_key (crypt_key_t * keys, if (i == keymax) { keymax += 20; - mem_realloc (&key_table, sizeof (crypt_key_t *) * keymax); + p_realloc(&key_table, keymax); } key_table[i++] = k; @@ -3768,7 +3767,7 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc, #endif keylist_size += str_len (s) + 4 + 1; - mem_realloc (&keylist, keylist_size); + p_realloc(&keylist, keylist_size); sprintf (keylist + keylist_used, "%s0x%s%s", /* __SPRINTF_CHECKED__ */ keylist_used ? " " : "", s, forced_valid ? "!" : ""); } diff --git a/crypt-mod.c b/crypt-mod.c index 6a93bad..9a43556 100644 --- a/crypt-mod.c +++ b/crypt-mod.c @@ -14,7 +14,6 @@ #include #include "crypt-mod.h" -#include "lib/mem.h" /* A type an a variable to keep track of registered crypto modules. */ typedef struct crypt_module *crypt_module_t; diff --git a/crypt.c b/crypt.c index dad41c3..e5019ec 100644 --- a/crypt.c +++ b/crypt.c @@ -27,7 +27,6 @@ #include "mutt_crypt.h" #include "pgp.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" @@ -699,7 +698,7 @@ int crypt_get_keys (HEADER * msg, char **keylist) -static void crypt_fetch_signatures (BODY *** signatures, BODY * a, int *n) +static void crypt_fetch_signatures (BODY ***signatures, BODY * a, int *n) { if (!WithCrypto) return; @@ -709,7 +708,7 @@ static void crypt_fetch_signatures (BODY *** signatures, BODY * a, int *n) crypt_fetch_signatures (signatures, a->parts, n); else { if ((*n % 5) == 0) - mem_realloc (signatures, (*n + 6) * sizeof (BODY **)); + p_realloc(signatures, *n + 6); (*signatures)[(*n)++] = a; } diff --git a/curs_lib.c b/curs_lib.c index 9f8b8aa..a5b3a22 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -24,7 +24,6 @@ #include "pager.h" #include "mbyte.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -490,7 +489,7 @@ void mutt_ungetch (int ch, int op) tmp.op = op; if (UngetCount >= UngetBufLen) - mem_realloc (&KeyEvent, (UngetBufLen += 128) * sizeof (event_t)); + p_realloc(&KeyEvent, UngetBufLen += 128); KeyEvent[UngetCount++] = tmp; } diff --git a/curs_main.c b/curs_main.c index 82f8402..1217c5e 100644 --- a/curs_main.c +++ b/curs_main.c @@ -47,7 +47,6 @@ #include "mutt_sasl.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/edit.c b/edit.c index 2f1a377..42a3bcf 100644 --- a/edit.c +++ b/edit.c @@ -21,7 +21,6 @@ #include "mutt_curses.h" #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" @@ -78,11 +77,11 @@ static char **be_snarf_data (FILE * f, char **buf, int *bufmax, int *buflen, break; bytes -= str_len (p); if (*bufmax == *buflen) - mem_realloc (&buf, sizeof (char *) * (*bufmax += 25)); + p_realloc(&buf, *bufmax += 25); buf[(*buflen)++] = str_dup (tmp); } if (buf && *bufmax == *buflen) { /* Do not smash memory past buf */ - mem_realloc (&buf, sizeof (char *) * (++*bufmax)); + p_realloc(&buf, ++*bufmax); } if (buf) buf[*buflen] = NULL; @@ -158,7 +157,7 @@ static char **be_include_messages (char *msg, char **buf, int *bufmax, } if (*bufmax == *buflen) - mem_realloc (&buf, sizeof (char *) * (*bufmax += 25)); + p_realloc(&buf, *bufmax += 25); buf[(*buflen)++] = str_dup (tmp); bytes = Context->hdrs[n]->content->length; @@ -172,7 +171,7 @@ static char **be_include_messages (char *msg, char **buf, int *bufmax, pfx); if (*bufmax == *buflen) - mem_realloc (&buf, sizeof (char *) * (*bufmax += 25)); + p_realloc(&buf, *bufmax += 25); buf[(*buflen)++] = str_dup ("\n"); } else @@ -442,7 +441,7 @@ int mutt_builtin_editor (const char *path, HEADER * msg, HEADER * cur) else { str_cat (tmp, sizeof (tmp), "\n"); if (buflen == bufmax) - mem_realloc (&buf, sizeof (char *) * (bufmax += 25)); + p_realloc(&buf, bufmax += 25); buf[buflen++] = str_dup (tmp[1] == '~' ? tmp + 1 : tmp); } diff --git a/enter.c b/enter.c index 1b97bd4..4841111 100644 --- a/enter.c +++ b/enter.c @@ -22,7 +22,6 @@ #include "history.h" #include "buffy.h" -#include "lib/mem.h" #include @@ -135,7 +134,7 @@ size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, char *buf) k != (size_t) (-1) && k != (size_t) (-2); buf += k) { if (i >= wbuflen) { wbuflen = i + 20; - mem_realloc (&wbuf, wbuflen * sizeof (*wbuf)); + p_realloc(&wbuf, wbuflen); } wbuf[i++] = wc; } @@ -161,7 +160,7 @@ static void replace_part (ENTER_STATE *state, size_t from, const char *buf) /* Make space for suffix */ if (state->curpos + savelen > state->wbuflen) { state->wbuflen = state->curpos + savelen; - mem_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t)); + p_realloc(&state->wbuf, state->wbuflen); } /* Restore suffix */ @@ -471,7 +470,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, } if (!mutt_complete (buf, buflen)) { templen = state->lastchar - i; - mem_realloc (&tempbuf, templen * sizeof (wchar_t)); + p_realloc(&tempbuf, templen); } else BEEP (); @@ -539,7 +538,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, if (!mutt_complete (buf, buflen)) { templen = state->lastchar; - mem_realloc (&tempbuf, templen * sizeof (wchar_t)); + p_realloc(&tempbuf, templen); memcpy (tempbuf, state->wbuf, templen * sizeof (wchar_t)); } else @@ -649,7 +648,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, else if (wc && (wc < ' ' || IsWPrint (wc))) { /* why? */ if (state->lastchar >= state->wbuflen) { state->wbuflen = state->lastchar + 20; - mem_realloc (&state->wbuf, state->wbuflen * sizeof (wchar_t)); + p_realloc(&state->wbuf, state->wbuflen); } memmove (state->wbuf + state->curpos + 1, state->wbuf + state->curpos, (state->lastchar - state->curpos) * sizeof (wchar_t)); diff --git a/from.c b/from.c index e3c85eb..cc61283 100644 --- a/from.c +++ b/from.c @@ -15,7 +15,6 @@ #include "mutt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/gnupgparse.c b/gnupgparse.c index 1166a91..ce4d92e 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -42,7 +42,6 @@ /* for hexval */ #include "mime.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/handler.c b/handler.c index 39bc056..a2481ac 100644 --- a/handler.c +++ b/handler.c @@ -36,7 +36,6 @@ #include "attach.h" #include "lib.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -517,7 +516,7 @@ static void enriched_flush (struct enriched_state *stte, int wrap) stte->line_used += stte->buff_used; if (stte->line_used > stte->line_max) { stte->line_max = stte->line_used; - mem_realloc (&stte->line, stte->line_max + 1); + p_realloc(&stte->line, stte->line_max + 1); } strcat (stte->line, stte->buffer); /* __STRCAT_CHECKED__ */ stte->line_len += stte->word_len; @@ -534,7 +533,7 @@ static void enriched_putc (int c, struct enriched_state *stte) if (stte->tag_level[RICH_PARAM]) { if (stte->tag_level[RICH_COLOR]) { if (stte->param_used + 1 >= stte->param_len) - mem_realloc (&stte->param, (stte->param_len += STRING)); + p_realloc(&stte->param, (stte->param_len += STRING)); stte->param[stte->param_used++] = c; } @@ -544,7 +543,7 @@ static void enriched_putc (int c, struct enriched_state *stte) /* see if more space is needed (plus extra for possible rich characters) */ if (stte->buff_len < stte->buff_used + 3) { stte->buff_len += LONG_STRING; - mem_realloc (&stte->buffer, stte->buff_len + 1); + p_realloc(&stte->buffer, stte->buff_len + 1); } if ((!stte->tag_level[RICH_NOFILL] && ISSPACE (c)) || c == '\0') { @@ -591,7 +590,7 @@ static void enriched_puts (const char *s, struct enriched_state *stte) if (stte->buff_len < stte->buff_used + str_len (s)) { stte->buff_len += LONG_STRING; - mem_realloc (&stte->buffer, stte->buff_len + 1); + p_realloc(&stte->buffer, stte->buff_len + 1); } p = s; diff --git a/hash.c b/hash.c index ac9dc1c..ef9346d 100644 --- a/hash.c +++ b/hash.c @@ -19,8 +19,6 @@ #include "mutt.h" -#include "lib/mem.h" - #define SOMEPRIME 149711 int hash_string (const unsigned char *s, int n) diff --git a/hcache.c b/hcache.c index e69a591..fd706db 100644 --- a/hcache.c +++ b/hcache.c @@ -51,7 +51,6 @@ #include "lib.h" #include "md5.h" -#include "lib/mem.h" #include "lib/debug.h" #if HAVE_QDBM @@ -101,7 +100,7 @@ static void lazy_realloc (void *ptr, size_t siz) return; } - mem_realloc (ptr, siz); + p_realloc(ptr, siz); } static unsigned char *dump_int (unsigned int i, unsigned char *d, int *off) diff --git a/history.c b/history.c index 304c7b9..215a0ef 100644 --- a/history.c +++ b/history.c @@ -15,7 +15,6 @@ #include "mutt.h" #include "history.h" -#include "lib/mem.h" /* global vars used for the string-history routines */ diff --git a/hook.c b/hook.c index 62fc7ff..a3a25e3 100644 --- a/hook.c +++ b/hook.c @@ -22,7 +22,6 @@ #include "compress.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" diff --git a/imap/auth.c b/imap/auth.c index 4861fbb..f97e5a9 100644 --- a/imap/auth.c +++ b/imap/auth.c @@ -17,7 +17,6 @@ #include -#include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index f9be180..171aadd 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -21,7 +21,6 @@ #include "imap_private.h" #include "auth.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" diff --git a/imap/browse.c b/imap/browse.c index 73bfcbc..52dcc79 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -19,7 +19,6 @@ #include -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" #include "lib/debug.h" @@ -394,11 +393,9 @@ static void imap_add_folder (char delim, char *folder, int noselect, imap_unmunge_mbox_name (folder); if (state->entrylen + 1 == state->entrymax) { - mem_realloc (&state->entry, - sizeof (struct folder_file) * (state->entrymax += 256)); - memset (state->entry + state->entrylen, 0, - (sizeof (struct folder_file) * - (state->entrymax - state->entrylen))); + p_realloc(&state->entry, state->entrymax += 256); + p_clear(state->entry + state->entrylen, + state->entrymax - state->entrylen); } /* render superiors as unix-standard ".." */ diff --git a/imap/command.c b/imap/command.c index 1232457..570e063 100644 --- a/imap/command.c +++ b/imap/command.c @@ -18,7 +18,6 @@ #include -#include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" @@ -105,7 +104,7 @@ int imap_cmd_step (IMAP_DATA * idata) * line */ do { if (len == cmd->blen) { - mem_realloc (&cmd->buf, cmd->blen + IMAP_CMD_BUFSIZE); + p_realloc(&cmd->buf, cmd->blen + IMAP_CMD_BUFSIZE); cmd->blen = cmd->blen + IMAP_CMD_BUFSIZE; debug_print (3, ("grew buffer to %u bytes\n", cmd->blen)); } @@ -129,7 +128,7 @@ int imap_cmd_step (IMAP_DATA * idata) /* don't let one large string make cmd->buf hog memory forever */ if ((cmd->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) { - mem_realloc (&cmd->buf, IMAP_CMD_BUFSIZE); + p_realloc(&cmd->buf, IMAP_CMD_BUFSIZE); cmd->blen = IMAP_CMD_BUFSIZE; debug_print (3, ("shrank buffer to %u bytes\n", cmd->blen)); } diff --git a/imap/imap.c b/imap/imap.c index 3f988e8..17e94a2 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -31,7 +31,6 @@ #endif #include "buffy.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/imap/message.c b/imap/message.c index 4781a36..7157df6 100644 --- a/imap/message.c +++ b/imap/message.c @@ -32,7 +32,6 @@ #include "pgp.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/imap/mx_imap.c b/imap/mx_imap.c index 53056fc..29abeec 100644 --- a/imap/mx_imap.c +++ b/imap/mx_imap.c @@ -17,7 +17,6 @@ #include "mx.h" #include "mx_imap.h" -#include "lib/mem.h" #include "lib/str.h" #include "url.h" diff --git a/imap/utf7.c b/imap/utf7.c index 7eeed83..f4a84a1 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -17,8 +17,6 @@ #include "charset.h" #include "imap_private.h" -#include "lib/mem.h" - static int Index_64[128] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -115,7 +113,7 @@ static char *utf7_to_utf8 (const char *u7, size_t u7len, char **u8, if (u8len) *u8len = p - buf; - mem_realloc (&buf, p - buf); + p_realloc(&buf, p - buf); if (u8) *u8 = buf; return buf; @@ -221,7 +219,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7, *p++ = '\0'; if (u7len) *u7len = p - buf; - mem_realloc (&buf, p - buf); + p_realloc(&buf, p - buf); if (u7) *u7 = buf; return buf; diff --git a/imap/util.c b/imap/util.c index 8bb4dcf..9cf7043 100644 --- a/imap/util.c +++ b/imap/util.c @@ -22,7 +22,6 @@ #include "imap_private.h" #include "mutt_ssl.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" diff --git a/init.c b/init.c index ab1e583..3af5cd5 100644 --- a/init.c +++ b/init.c @@ -40,7 +40,6 @@ #include "mx.h" #include "init.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" diff --git a/keymap.c b/keymap.c index a879852..73234e1 100644 --- a/keymap.c +++ b/keymap.c @@ -22,7 +22,6 @@ #include "mapping.h" #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/lib-lib/mem.h b/lib-lib/mem.h index c1eb0b1..c95feac 100644 --- a/lib-lib/mem.h +++ b/lib-lib/mem.h @@ -23,49 +23,20 @@ #include #include -static inline void *xmalloc(ssize_t size) { - void *mem; - - if (size <= 0) - return NULL; - - mem = calloc(size, 1); - if (!mem) - abort(); - return mem; -} - -static inline void *xrealloc(void *mem, ssize_t newsize) { - mem = realloc(mem, newsize); - if (!mem) - abort(); - return mem; -} - -static inline void *xmemdup(const void *src, ssize_t size) { - return memcpy(xmalloc(size), src, size); -} - -static inline void *xmemdupstr(const void *src, ssize_t len) { - char *res = xmalloc(len + 1); - memcpy(res, src, len); - res[len] = '\0'; - return res; -} - #define p_new(type, count) ((type *)xmalloc(sizeof(type) * (count))) #define p_clear(p, count) ((void)memset((p), 0, sizeof(*(p)) * (count))) #define p_dup(p, count) xmemdup((p), sizeof(*(p)) * (count)) #define p_dupstr(p, len) xmemdupstr((p), (len)) +#define p_realloc(pp, count) xrealloc((void*)(pp), sizeof(**(pp)) * (count)) #ifdef __GNUC__ # define p_delete(mem_pp) \ - ({ \ + do { \ typeof(**(mem_pp)) **__ptr = (mem_pp); \ free(*__ptr); \ *__ptr = NULL; \ - }) + } while(0) #else @@ -78,8 +49,40 @@ static inline void *xmemdupstr(const void *src, ssize_t len) { #endif +static inline void *xmalloc(ssize_t size) { + void *mem; + + if (size <= 0) + return NULL; + + mem = calloc(size, 1); + if (!mem) + abort(); + return mem; +} + static inline void xmemfree(void **ptr) { p_delete(ptr); } +static inline void xrealloc(void **ptr, ssize_t newsize) { + if (newsize <= 0) { + p_delete(ptr); + } else { + *ptr = realloc(*ptr, newsize); + if (!*ptr) + abort(); + } +} + +static inline void *xmemdup(const void *src, ssize_t size) { + return memcpy(xmalloc(size), src, size); +} + +static inline void *xmemdupstr(const void *src, ssize_t len) { + char *res = memcpy(xmalloc(len + 1), src, len); + res[len] = '\0'; + return res; +} + #endif /* MUTT_LIB_LIB_MEM_H */ diff --git a/lib.c b/lib.c index e683c6d..eee11e5 100644 --- a/lib.c +++ b/lib.c @@ -38,7 +38,6 @@ #include "lib.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/debug.h" @@ -435,7 +434,7 @@ char *mutt_read_line(char *s, size_t * size, FILE * fp, int *line) /* There wasn't room for the line -- increase ``s'' */ offset = *size - 1; /* overwrite the terminating 0 */ *size += STRING; - mem_realloc (&s, *size); + p_realloc(&s, *size); } } } diff --git a/lib/Makefile.am b/lib/Makefile.am index b6bc751..9d687ab 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = -I$(top_srcdir) -I../intl noinst_LIBRARIES = libsane.a noinst_HEADERS = str.h exit.h intl.h list.h rx.h debug.h -libsane_a_SOURCES = mem.h exit.c str.c list.c rx.h debug.h \ - mem.c exit.h str.h list.h rx.c debug.c intl.h +libsane_a_SOURCES = exit.c str.c list.c rx.h debug.h \ + exit.h str.h list.h rx.c debug.c intl.h -include ../cflags.mk diff --git a/lib/list.c b/lib/list.c index efa4c98..23dcf26 100644 --- a/lib/list.c +++ b/lib/list.c @@ -14,7 +14,6 @@ #include "list.h" -#include "mem.h" #include "str.h" list2_t* list_new (void) { @@ -35,14 +34,14 @@ void list_del (list2_t** l, list_del_t* del) { void list_push_back (list2_t** l, void* p) { if (!*l) *l = list_new (); - mem_realloc (&(*l)->data, (++(*l)->length)*sizeof(void*)); + p_realloc(&(*l)->data, ++(*l)->length); (*l)->data[(*l)->length-1] = p; } void list_push_front (list2_t** l, void* p) { if (!*l) *l = list_new (); - mem_realloc (&(*l)->data, (++(*l)->length)*sizeof(void*)); + p_realloc(&(*l)->data, ++(*l)->length); if ((*l)->length > 1) memmove (&(*l)->data[1], &(*l)->data[0], ((*l)->length-1)*sizeof(void*)); (*l)->data[0] = p; @@ -53,7 +52,7 @@ void* list_pop_back (list2_t* l) { if (list_empty(l)) return (NULL); p = l->data[l->length-1]; - mem_realloc (&l->data, --(l->length)*sizeof(void*)); + p_realloc(&l->data, --(l->length)); return (p); } @@ -63,7 +62,7 @@ void* list_pop_front (list2_t* l) { return (NULL); p = l->data[0]; memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*)); - mem_realloc (&l->data, l->length*sizeof(void*)); + p_realloc(&l->data, l->length); return (p); } @@ -75,7 +74,7 @@ void* list_pop_idx (list2_t* l, int c) { return (list_pop_back (l)); p = l->data[c]; memmove (&l->data[c], &l->data[c+1], (l->length-c)*sizeof(void*)); - mem_realloc (&l->data, (--(l->length))*sizeof(void*)); + p_realloc(&l->data, --(l->length)); return (p); } diff --git a/lib/mem.c b/lib/mem.c deleted file mode 100644 index df2e2ed..0000000 --- a/lib/mem.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ - -#include - -#include "mem.h" -#include "exit.h" -#include "intl.h" - -void _mem_realloc (void *ptr, size_t siz, int line, const char* fname) { - void *r; - void **p = (void **) ptr; - - if (siz == 0) { - if (*p) { - free (*p); /* __MEM_CHECKED__ */ - *p = NULL; - } - return; - } - - if (*p) - r = (void *) realloc (*p, siz); /* __MEM_CHECKED__ */ - else { - /* realloc(NULL, nbytes) doesn't seem to work under SunOS 4.1.x --- __MEM_CHECKED__ */ - r = (void *) malloc (siz); /* __MEM_CHECKED__ */ - } - - if (!r) - exit_fatal ("mem_realloc", _("Out of memory!"), line, fname, 1); - - *p = r; -} diff --git a/lib/mem.h b/lib/mem.h deleted file mode 100644 index ac8f811..0000000 --- a/lib/mem.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This file is part of mutt-ng, see http://www.muttng.org/. - * It's licensed under the GNU General Public License, - * please see the file GPL in the top level source directory. - */ -#ifndef _LIB_MEM_H -#define _LIB_MEM_H - -#include - -void _mem_realloc (void*, size_t, int, const char*); -#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 616d824..4465255 100644 --- a/lib/rx.c +++ b/lib/rx.c @@ -12,7 +12,6 @@ #include "rx.h" -#include "mem.h" #include "str.h" rx_t *rx_compile (const char *s, int flags) { diff --git a/lib/str.c b/lib/str.c index 11c27b3..e40e614 100644 --- a/lib/str.c +++ b/lib/str.c @@ -16,8 +16,6 @@ #include "str.h" -#include "mem.h" - char *str_dup (const char *s) { if (!s || !*s) @@ -103,7 +101,7 @@ void str_adjust (char **p) { if (!p || !*p) return; - mem_realloc (p, str_len (*p) + 1); + p_realloc(p, str_len (*p) + 1); } /* convert all characters in the string to lowercase */ diff --git a/list.c b/list.c index b40e97b..550604a 100644 --- a/list.c +++ b/list.c @@ -16,7 +16,6 @@ #include #include "list.h" -#include "lib/mem.h" #include "lib/str.h" LIST *mutt_copy_list (LIST * p) { diff --git a/main.c b/main.c index d703022..d0c4b0c 100644 --- a/main.c +++ b/main.c @@ -29,7 +29,6 @@ #include "mutt_idna.h" #include "xterm.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/mbox.c b/mbox.c index 7a5d875..4a12c19 100644 --- a/mbox.c +++ b/mbox.c @@ -27,7 +27,6 @@ #include "compress.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/menu.c b/menu.c index 51c0b1a..1431797 100644 --- a/menu.c +++ b/menu.c @@ -24,7 +24,6 @@ #include "imap.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/mh.c b/mh.c index ee799b3..8c9bbc7 100644 --- a/mh.c +++ b/mh.c @@ -29,7 +29,6 @@ #include "thread.h" #include "hcache.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -85,7 +84,7 @@ static void mhs_alloc (struct mh_sequences *mhs, int i) if (i > mhs->max || !mhs->flags) { newmax = i + 128; - mem_realloc (&mhs->flags, sizeof (mhs->flags[0]) * (newmax + 1)); + p_realloc(&mhs->flags, newmax + 1); for (j = mhs->max + 1; j <= newmax; j++) mhs->flags[j] = 0; diff --git a/mutt_idna.c b/mutt_idna.c index 5078717..96d33d2 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -18,7 +18,6 @@ #include "charset.h" #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -157,7 +156,7 @@ int mutt_addrlist_to_idna (ADDRESS * a, char **err) *err = str_dup (domain); } else { - mem_realloc (&a->mailbox, str_len (user) + str_len (tmp) + 2); + p_realloc(&a->mailbox, str_len(user) + str_len(tmp) + 2); sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ } @@ -184,7 +183,7 @@ int mutt_addrlist_to_local (ADDRESS * a) continue; if (mutt_idna_to_local (domain, &tmp, 0) == 0) { - mem_realloc (&a->mailbox, str_len (user) + str_len (tmp) + 2); + p_realloc(&a->mailbox, str_len(user) + str_len(tmp) + 2); sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ } @@ -218,7 +217,7 @@ const char *mutt_addr_for_display (ADDRESS * a) return a->mailbox; } - mem_realloc (&buff, str_len (tmp) + str_len (user) + 2); + p_realloc(&buff, str_len(tmp) + str_len(user) + 2); sprintf (buff, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ p_delete(&tmp); p_delete(&user); diff --git a/mutt_libesmtp.c b/mutt_libesmtp.c index 5524844..0a6547f 100644 --- a/mutt_libesmtp.c +++ b/mutt_libesmtp.c @@ -20,7 +20,6 @@ #include "ascii.h" #include "enter.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/mutt_sasl.c b/mutt_sasl.c index da5ac5f..5bc1b70 100644 --- a/mutt_sasl.c +++ b/mutt_sasl.c @@ -20,7 +20,6 @@ #include "mutt_sasl.h" #include "mutt_socket.h" -#include "lib/mem.h" #include "lib/debug.h" #include diff --git a/mutt_socket.c b/mutt_socket.c index 1c3d865..6bac9d4 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -25,7 +25,6 @@ #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/mutt_ssl.c b/mutt_ssl.c index 6a83032..37e46b6 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -30,7 +30,6 @@ #include "mutt_curses.h" #include "mutt_ssl.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/mutt_ssl_gnutls.c b/mutt_ssl_gnutls.c index 91b03dd..134828b 100644 --- a/mutt_ssl_gnutls.c +++ b/mutt_ssl_gnutls.c @@ -28,7 +28,6 @@ #include "mutt_menu.h" #include "mutt_ssl.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" #include "lib/rx.h" diff --git a/mutt_tunnel.c b/mutt_tunnel.c index 6c5a7a3..e26261a 100644 --- a/mutt_tunnel.c +++ b/mutt_tunnel.c @@ -18,7 +18,6 @@ #include "mutt_socket.h" #include "mutt_tunnel.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/muttlib.c b/muttlib.c index 0e4027a..bb6ac73 100644 --- a/muttlib.c +++ b/muttlib.c @@ -34,7 +34,6 @@ #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -1335,7 +1334,7 @@ int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x) for (; l; l = l->next) { /* If this pattern needs more matches, expand pmatch. */ if (l->nmatch > nmatch) { - mem_realloc (&pmatch, l->nmatch * sizeof (regmatch_t)); + p_realloc(&pmatch, l->nmatch); nmatch = l->nmatch; } diff --git a/mx.c b/mx.c index c68b0ac..9400483 100644 --- a/mx.c +++ b/mx.c @@ -53,7 +53,6 @@ #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/list.h" @@ -1310,8 +1309,8 @@ void mx_alloc_memory (CONTEXT * ctx) } if (ctx->hdrs) { - mem_realloc (&ctx->hdrs, sizeof (HEADER *) * (ctx->hdrmax += 25)); - mem_realloc (&ctx->v2r, sizeof (int) * ctx->hdrmax); + p_realloc(&ctx->hdrs, ctx->hdrmax += 25); + p_realloc(&ctx->v2r, ctx->hdrmax); } else { ctx->hdrs = p_new(HEADER *, (ctx->hdrmax += 25)); diff --git a/nntp/mx_nntp.c b/nntp/mx_nntp.c index bc1d77d..84a9d64 100644 --- a/nntp/mx_nntp.c +++ b/nntp/mx_nntp.c @@ -17,7 +17,6 @@ #include "mx.h" #include "mx_nntp.h" -#include "lib/mem.h" #include "lib/str.h" #include "url.h" diff --git a/nntp/newsrc.c b/nntp/newsrc.c index b711b2f..8f0e514 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -25,7 +25,6 @@ #include "rfc1524.h" #include "rfc2047.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" #include "lib/debug.h" @@ -510,7 +509,7 @@ static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf, len += *buflen; *buflen *= 2; line = *buf; - mem_realloc (buf, *buflen); + p_realloc(buf, *buflen); line = *buf + (*pline - line); } strcpy (line, data->group); @@ -526,7 +525,7 @@ static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf, *buflen *= 2; *pline = line; line = *buf; - mem_realloc (buf, *buflen); + p_realloc(buf, *buflen); line = *buf + (*pline - line); } if (x) { @@ -596,7 +595,7 @@ void newsrc_gen_entries (CONTEXT * ctx) !ctx->hdrs[x]->read) { if (data->num >= data->max) { data->max = data->max * 2; - mem_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY)); + p_realloc(&data->entries, data->max); } data->entries[data->num].first = first; data->entries[data->num].last = last - 1; @@ -616,7 +615,7 @@ void newsrc_gen_entries (CONTEXT * ctx) if (series && first <= data->lastLoaded) { if (data->num >= data->max) { data->max = data->max * 2; - mem_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY)); + p_realloc(&data->entries, data->max); } data->entries[data->num].first = first; data->entries[data->num].last = data->lastLoaded; diff --git a/nntp/nntp.c b/nntp/nntp.c index 9674316..34c035f 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -29,7 +29,6 @@ #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" #include "lib/debug.h" @@ -390,7 +389,7 @@ static int mutt_nntp_fetch (NNTP_DATA * nntp_data, const char *query, char *msg, lenbuf = 0; } - mem_realloc (&inbuf, lenbuf + sizeof (buf)); + p_realloc(&inbuf, lenbuf + sizeof (buf)); } p_delete(&inbuf); funct (NULL, data); @@ -1498,7 +1497,7 @@ static int check_children (char *s, void *c) if (cc->ctx->hdrs[i]->article_num == n) return 0; if (cc->num >= cc->max) - mem_realloc (&cc->child, sizeof (unsigned int) * (cc->max += 25)); + p_realloc(&cc->child, cc->max += 25); cc->child[cc->num++] = n; return 0; diff --git a/pager.c b/pager.c index 31f139a..bd1b2a8 100644 --- a/pager.c +++ b/pager.c @@ -39,7 +39,6 @@ #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" @@ -700,7 +699,7 @@ resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last, /* oops... */ if (lineInfo[i].chunks) { lineInfo[i].chunks = 0; - mem_realloc (&(lineInfo[n].syntax), sizeof (struct syntax_t)); + p_realloc(&(lineInfo[n].syntax), 1); } lineInfo[i++].type = MT_COLOR_SIGNATURE; } @@ -764,9 +763,7 @@ resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last, if (pmatch[0].rm_eo != pmatch[0].rm_so) { if (!found) { if (++(lineInfo[n].chunks) > 1) - mem_realloc (&(lineInfo[n].syntax), - (lineInfo[n].chunks) * - sizeof (struct syntax_t)); + p_realloc(&(lineInfo[n].syntax), lineInfo[n].chunks); } i = lineInfo[n].chunks - 1; pmatch[0].rm_so += offset; @@ -1147,7 +1144,7 @@ display_line (FILE * f, off_t *last_pos, struct line_t **lineInfo, int n, } if (*last == *max) { - mem_realloc (lineInfo, sizeof (struct line_t) * (*max += LINES)); + p_realloc(lineInfo, *max += LINES); for (ch = *last; ch < *max; ch++) { memset (&((*lineInfo)[ch]), 0, sizeof (struct line_t)); (*lineInfo)[ch].type = -1; @@ -1224,8 +1221,7 @@ display_line (FILE * f, off_t *last_pos, struct line_t **lineInfo, int n, (SearchRE, (char *) fmt + offset, 1, pmatch, (offset ? REG_NOTBOL : 0)) == 0) { if (++((*lineInfo)[n].search_cnt) > 1) - mem_realloc (&((*lineInfo)[n].search), - ((*lineInfo)[n].search_cnt) * sizeof (struct syntax_t)); + p_realloc(&(*lineInfo)[n].search, (*lineInfo)[n].search_cnt); else (*lineInfo)[n].search = p_new(struct syntax_t, 1); pmatch[0].rm_so += offset; @@ -1748,7 +1744,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) lineInfo[i].search_cnt = -1; lineInfo[i].quote = NULL; - mem_realloc (&(lineInfo[i].syntax), sizeof (struct syntax_t)); + p_realloc(&lineInfo[i].syntax, 1); if (SearchCompiled && lineInfo[i].search) p_delete(&(lineInfo[i].search)); } @@ -2230,7 +2226,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) lineInfo[i].search_cnt = -1; lineInfo[i].quote = NULL; - mem_realloc (&(lineInfo[i].syntax), sizeof (struct syntax_t)); + p_realloc(&(lineInfo[i].syntax), 1); if (SearchCompiled && lineInfo[i].search) p_delete(&(lineInfo[i].search)); } diff --git a/parse.c b/parse.c index 119959e..b429117 100644 --- a/parse.c +++ b/parse.c @@ -25,7 +25,6 @@ #include "mutt_crypt.h" #include "url.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" @@ -78,7 +77,7 @@ char *mutt_read_rfc822_line (FILE * f, char *line, size_t * linelen) if (*linelen < offset + STRING) { /* grow the buffer */ *linelen += STRING; - mem_realloc (&line, *linelen); + p_realloc(&line, *linelen); buf = line + offset; } } diff --git a/pattern.c b/pattern.c index 1ca87e4..eb371fc 100644 --- a/pattern.c +++ b/pattern.c @@ -24,7 +24,6 @@ #include "copy.h" #include "mime.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/pgp.c b/pgp.c index 4603a94..4adb5d0 100644 --- a/pgp.c +++ b/pgp.c @@ -33,7 +33,6 @@ #include "copy.h" #include "attach.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -1174,7 +1173,7 @@ char *pgp_findKeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc) bypass_selection: keylist_size += str_len (keyID) + 4; - mem_realloc (&keylist, keylist_size); + p_realloc(&keylist, keylist_size); sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */ keyID); keylist_used = str_len (keylist); diff --git a/pgpinvoke.c b/pgpinvoke.c index 26d1d42..0cef580 100644 --- a/pgpinvoke.c +++ b/pgpinvoke.c @@ -33,7 +33,6 @@ #include "pgp.h" #include "rfc822.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/pgpkey.c b/pgpkey.c index 1136ee5..2ac3ce1 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -25,7 +25,6 @@ #include "pager.h" #include "sort.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -455,7 +454,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s) if (i == keymax) { keymax += 5; - mem_realloc (&KeyTable, sizeof (pgp_uid_t *) * keymax); + p_realloc(&KeyTable, keymax); } KeyTable[i++] = a; diff --git a/pgplib.c b/pgplib.c index f0ffda8..36f24a4 100644 --- a/pgplib.c +++ b/pgplib.c @@ -25,8 +25,6 @@ #include "lib.h" #include "pgplib.h" -#include "lib/mem.h" - const char *pgp_pkalgbytype (unsigned char type) { switch (type) { diff --git a/pgppacket.c b/pgppacket.c index 7fd8962..add9945 100644 --- a/pgppacket.c +++ b/pgppacket.c @@ -24,8 +24,6 @@ #include "pgplib.h" #include "pgppacket.h" -#include "lib/mem.h" - #define CHUNKSIZE 1024 static unsigned char *pbuf = NULL; diff --git a/pgppubring.c b/pgppubring.c index 20b4b92..0ab6a53 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -28,7 +28,6 @@ #include -#include "lib/mem.h" #include "lib/str.h" #include diff --git a/pop/mx_pop.c b/pop/mx_pop.c index 34b6b45..0b6d9e5 100644 --- a/pop/mx_pop.c +++ b/pop/mx_pop.c @@ -17,7 +17,6 @@ #include "mx.h" #include "mx_pop.h" -#include "lib/mem.h" #include "lib/str.h" #include "url.h" diff --git a/pop/pop.c b/pop/pop.c index 1b70009..465a770 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -19,7 +19,6 @@ #include "mutt_crypt.h" #include "mutt_curses.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" #include "lib/debug.h" diff --git a/pop/pop_auth.c b/pop/pop_auth.c index 9382072..08d3183 100644 --- a/pop/pop_auth.c +++ b/pop/pop_auth.c @@ -19,7 +19,6 @@ #include "md5.h" #include "pop.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" diff --git a/pop/pop_lib.c b/pop/pop_lib.c index 603fa05..8359cac 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -22,7 +22,6 @@ # include "mutt_ssl.h" #endif -#include "lib/mem.h" #include "lib/intl.h" #include "lib/debug.h" #include "lib/str.h" @@ -116,8 +115,8 @@ static int fetch_auth (char *line, void *data) if (!pop_data->auth_list) { pop_data->auth_list = p_new(char, strlen(line) + 1); } else { - mem_realloc (&pop_data->auth_list, - strlen (pop_data->auth_list) + strlen (line) + 2); + p_realloc(&pop_data->auth_list, + strlen(pop_data->auth_list) + strlen(line) + 2); strcat (pop_data->auth_list, " "); /* __STRCAT_CHECKED__ */ } strcat (pop_data->auth_list, line); /* __STRCAT_CHECKED__ */ @@ -463,7 +462,7 @@ pop_query_status pop_fetch_data (POP_DATA * pop_data, const char *query, progres p++; } - strfcpy (inbuf + lenbuf, p, sizeof (buf)); + strfcpy(inbuf + lenbuf, p, sizeof(buf)); pos += chunk; if (chunk >= sizeof (buf)) { @@ -477,7 +476,7 @@ pop_query_status pop_fetch_data (POP_DATA * pop_data, const char *query, progres lenbuf = 0; } - mem_realloc (&inbuf, lenbuf + sizeof (buf)); + p_realloc(&inbuf, lenbuf + sizeof(buf)); } p_delete(&inbuf); diff --git a/postpone.c b/postpone.c index f7d7328..f4f5aa6 100644 --- a/postpone.c +++ b/postpone.c @@ -31,7 +31,6 @@ #endif #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/query.c b/query.c index ba3a5a4..58ece1f 100644 --- a/query.c +++ b/query.c @@ -19,7 +19,6 @@ #include "mapping.h" #include "sort.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -355,7 +354,7 @@ static void query_menu (char *buf, size_t buflen, QUERY * results, int retbuf) int clear = 0; /* append */ - mem_realloc (&QueryTable, menu->max * sizeof (ENTRY)); + p_realloc(&QueryTable, menu->max); menu->data = QueryTable; diff --git a/recvattach.c b/recvattach.c index e71d85b..6277705 100644 --- a/recvattach.c +++ b/recvattach.c @@ -29,7 +29,6 @@ #include "copy.h" #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" @@ -128,7 +127,7 @@ ATTACHPTR **mutt_gen_attach_list (BODY * m, for (; m; m = m->next) { if (*idxlen == *idxmax) { - mem_realloc (&idx, sizeof (ATTACHPTR *) * ((*idxmax) += 5)); + p_realloc(&idx, (*idxmax) += 5); for (i = *idxlen; i < *idxmax; i++) idx[i] = NULL; } diff --git a/recvcmd.c b/recvcmd.c index 8f59859..5606c28 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -28,7 +28,6 @@ #include "copy.h" #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/remailer.c b/remailer.c index 6181c73..b542209 100644 --- a/remailer.c +++ b/remailer.c @@ -25,7 +25,6 @@ #include "remailer.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" @@ -105,7 +104,7 @@ static void mix_add_entry (REMAILER *** type2_list, REMAILER * entry, { if (*used == *slots) { *slots += 5; - mem_realloc (type2_list, sizeof (REMAILER *) * (*slots)); + p_realloc(type2_list, *slots); } (*type2_list)[(*used)++] = entry; @@ -233,7 +232,7 @@ static void mix_screen_coordinates (REMAILER ** type2_list, if (!chain->cl) return; - mem_realloc (coordsp, sizeof (struct coord) * chain->cl); + p_realloc(coordsp, chain->cl); coords = *coordsp; diff --git a/rfc1524.c b/rfc1524.c index 026050f..5b70e5a 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -28,7 +28,6 @@ #include "rfc1524.h" #include "attach.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -270,7 +269,7 @@ static int rfc1524_mailcap_parse (BODY * a, if (get_field_text (field + 4, &test_command, type, filename, line) && test_command) { len = str_len (test_command) + STRING; - mem_realloc (&test_command, len); + p_realloc(&test_command, len); rfc1524_expand_command (a, a->filename, type, test_command, len); if (mutt_system (test_command)) { /* a non-zero exit code means test failed */ diff --git a/rfc2047.c b/rfc2047.c index ae4a52b..9452b3b 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -21,7 +21,6 @@ #include "rfc2047.h" #include "thread.h" -#include "lib/mem.h" #include "lib/str.h" #include @@ -77,7 +76,7 @@ static size_t convert_string (const char *f, size_t flen, *tlen = ob - buf; - mem_realloc (&buf, ob - buf + 1); + p_realloc(&buf, ob - buf + 1); *t = buf; iconv_close (cd); @@ -482,7 +481,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, #define LINEBREAK "\n\t" if (bufpos + wlen + str_len (LINEBREAK) > buflen) { buflen = bufpos + wlen + str_len (LINEBREAK); - mem_realloc (&buf, buflen); + p_realloc(&buf, buflen); } r = encode_block (buf + bufpos, t, n, icode, tocode, encoder); assert (r == wlen); @@ -498,7 +497,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, /* Add last encoded word and us-ascii suffix to buffer. */ buflen = bufpos + wlen + (u + ulen - t1); - mem_realloc (&buf, buflen + 1); + p_realloc(&buf, buflen + 1); r = encode_block (buf + bufpos, t, t1 - t, icode, tocode, encoder); assert (r == wlen); bufpos += wlen; diff --git a/rfc2231.c b/rfc2231.c index 29d60df..778995b 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -31,8 +31,6 @@ #include "rfc2047.h" #include "rfc2231.h" -#include "lib/mem.h" - #include #include #include @@ -274,7 +272,7 @@ static void rfc2231_join_continuations (PARAMETER ** head, vl = str_len (par->value); - mem_realloc (&value, l + vl + 1); + p_realloc(&value, l + vl + 1); strcpy (value + l, par->value); /* __STRCPY_CHECKED__ */ l += vl; diff --git a/rfc3676.c b/rfc3676.c index d359f25..cc14441 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -29,7 +29,6 @@ #include "state.h" #include "lib.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -212,7 +211,7 @@ int rfc3676_handler (BODY * a, STATE * s) { curline_len = 1; } - mem_realloc (&curline, curline_len + buf_len - buf_off); + p_realloc(&curline, curline_len + buf_len - buf_off); strcpy (curline + curline_len - 1, buf + buf_off); curline_len += buf_len - buf_off; diff --git a/rfc822.c b/rfc822.c index 18c980f..557f854 100644 --- a/rfc822.c +++ b/rfc822.c @@ -21,7 +21,6 @@ #include "ascii.h" #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/score.c b/score.c index 7fe90f6..88c42c3 100644 --- a/score.c +++ b/score.c @@ -17,7 +17,6 @@ #include "sort.h" #include "buffer.h" -#include "lib/mem.h" #include "lib/intl.h" #include diff --git a/send.c b/send.c index d2a743a..9e40423 100644 --- a/send.c +++ b/send.c @@ -28,7 +28,6 @@ #include "url.h" #include "attach.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" diff --git a/sendlib.c b/sendlib.c index e1c8a3d..f17b0d5 100644 --- a/sendlib.c +++ b/sendlib.c @@ -30,7 +30,6 @@ #include "mutt_crypt.h" #include "mutt_idna.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" #include "lib/debug.h" @@ -1441,7 +1440,7 @@ void mutt_write_references (LIST * r, FILE * f) for (; (TrimRef == 0 || refcnt < TrimRef) && r; r = r->next) { if (refcnt == refmax) - mem_realloc (&ref, (refmax += REF_INC) * sizeof (LIST *)); + p_realloc(&ref, refmax += REF_INC); ref[refcnt++] = r; } @@ -1650,8 +1649,7 @@ static void encode_headers (LIST * h) continue; rfc2047_encode_string (&tmp); - mem_realloc (&h->data, - str_len (h->data) + 2 + str_len (tmp) + 1); + p_realloc(&h->data, str_len(h->data) + 2 + str_len(tmp) + 1); sprintf (h->data + i, ": %s", NONULL (tmp)); /* __SPRINTF_CHECKED__ */ @@ -1953,7 +1951,7 @@ add_args(const char **args, size_t *argslen, size_t *argsmax, ADDRESS * addr) /* weed out group mailboxes, since those are for display only */ if (addr->mailbox && !addr->group) { if (*argslen == *argsmax) - mem_realloc (&args, (*argsmax += 5) * sizeof (char *)); + p_realloc(&args, *argsmax += 5); args[(*argslen)++] = addr->mailbox; } } @@ -1964,7 +1962,7 @@ static const char ** add_option(const char **args, size_t *argslen, size_t *argsmax, const char *s) { if (*argslen == *argsmax) { - mem_realloc(&args, (*argsmax += 5) * sizeof (char *)); + p_realloc(&args, *argsmax += 5); } args[(*argslen)++] = s; return (args); @@ -2002,7 +2000,7 @@ static int mutt_invoke_sendmail (ADDRESS * from, /* the sender */ i = 0; while ((ps = strtok (ps, " "))) { if (argslen == argsmax) - mem_realloc (&args, sizeof (char *) * (argsmax += 5)); + p_realloc(&args, argsmax += 5); if (i) args[argslen++] = ps; @@ -2053,7 +2051,7 @@ static int mutt_invoke_sendmail (ADDRESS * from, /* the sender */ #endif if (argslen == argsmax) - mem_realloc (&args, sizeof (char *) * (++argsmax)); + p_realloc(&args, ++argsmax); args[argslen++] = NULL; @@ -2112,7 +2110,7 @@ char *mutt_append_string (char *a, const char *b) { size_t la = str_len (a); - mem_realloc (&a, la + str_len (b) + 1); + p_realloc(&a, la + str_len(b) + 1); strcpy (a + la, b); /* __STRCPY_CHECKED__ */ return (a); } @@ -2147,7 +2145,7 @@ char *mutt_quote_string (const char *s) if (INVALID_CHAR (*s)) { size_t o = pr - r; - mem_realloc (&r, ++rlen); + p_realloc(&r, ++rlen); pr = r + o; *pr++ = '\\'; } diff --git a/sidebar.c b/sidebar.c index ea4f458..378c163 100644 --- a/sidebar.c +++ b/sidebar.c @@ -21,7 +21,6 @@ #include "buffy.h" #include "keymap.h" -#include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" diff --git a/smime.c b/smime.c index 728d111..9860826 100644 --- a/smime.c +++ b/smime.c @@ -24,7 +24,6 @@ #include "mime.h" #include "copy.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/debug.h" @@ -775,7 +774,7 @@ char *smime_findKeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc) } keylist_size += str_len (keyID) + 2; - mem_realloc (&keylist, keylist_size); + p_realloc(&keylist, keylist_size); sprintf (keylist + keylist_used, "%s\n", keyID); /* __SPRINTF_CHECKED__ */ keylist_used = str_len (keylist); diff --git a/status.c b/status.c index f95eb32..cc3d0d3 100644 --- a/status.c +++ b/status.c @@ -21,7 +21,6 @@ #include "mx.h" #include "buffy.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" diff --git a/thread.c b/thread.c index f64dc3f..965c897 100644 --- a/thread.c +++ b/thread.c @@ -17,7 +17,6 @@ #include "sort.h" #include "thread.h" -#include "lib/mem.h" #include "lib/intl.h" #include @@ -581,7 +580,7 @@ THREAD *mutt_sort_subthreads (THREAD * thread, int init) /* put them into the array */ for (i = 0; thread; i++, thread = thread->prev) { if (i >= array_size) - mem_realloc (&array, (array_size *= 2) * sizeof (THREAD *)); + p_realloc(&array, array_size *= 2); array[i] = thread; } diff --git a/url.c b/url.c index df231f3..9062dce 100644 --- a/url.c +++ b/url.c @@ -24,8 +24,6 @@ #include "mime.h" -#include "lib/mem.h" - #include static struct mapping_t UrlMap[] = { -- 2.20.1