From: Richard Russon Date: Wed, 28 Mar 2018 17:24:23 +0000 (+0100) Subject: cppcheck: reduce scope of variables X-Git-Tag: neomutt-20180512~65^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eaf1308a1f0f894fc558a61aee0f73bfd1ee750d;p=neomutt cppcheck: reduce scope of variables --- diff --git a/browser.c b/browser.c index e09dfd0c2..450e75a3d 100644 --- a/browser.c +++ b/browser.c @@ -1030,8 +1030,6 @@ static void browser_highlight_default(struct BrowserState *state, struct Menu *m static void init_menu(struct BrowserState *state, struct Menu *menu, char *title, size_t titlelen, bool buffy) { - char path[_POSIX_PATH_MAX]; - menu->max = state->entrylen; if (menu->current >= menu->max) @@ -1062,6 +1060,7 @@ static void init_menu(struct BrowserState *state, struct Menu *menu, } else { + char path[_POSIX_PATH_MAX]; menu->is_mailbox_list = 0; mutt_str_strfcpy(path, LastDir, sizeof(path)); mutt_pretty_mailbox(path, sizeof(path)); @@ -2013,12 +2012,11 @@ void mutt_select_file(char *f, size_t flen, int flags, char ***files, int *numfi } else { - struct Body *b = NULL; char buf2[_POSIX_PATH_MAX]; mutt_file_concat_path(buf2, LastDir, state.entry[menu->current].name, sizeof(buf2)); - b = mutt_make_file_attach(buf2); + struct Body *b = mutt_make_file_attach(buf2); if (b) { mutt_view_attachment(NULL, b, MUTT_REGULAR, NULL, NULL); diff --git a/buffy.c b/buffy.c index afbd34035..73276f141 100644 --- a/buffy.c +++ b/buffy.c @@ -158,13 +158,11 @@ static int test_new_folder(const char *path) static struct Buffy *buffy_new(const char *path) { - struct Buffy *buffy = NULL; char rp[PATH_MAX] = ""; - char *r = NULL; - buffy = mutt_mem_calloc(1, sizeof(struct Buffy)); + struct Buffy *buffy = mutt_mem_calloc(1, sizeof(struct Buffy)); mutt_str_strfcpy(buffy->path, path, sizeof(buffy->path)); - r = realpath(path, rp); + char *r = realpath(path, rp); mutt_str_strfcpy(buffy->realpath, r ? rp : path, sizeof(buffy->realpath)); buffy->next = NULL; buffy->magic = 0; @@ -804,9 +802,7 @@ int mutt_buffy_list(void) void mutt_buffy_setnotified(const char *path) { - struct Buffy *buffy = NULL; - - buffy = buffy_get(path); + struct Buffy *buffy = buffy_get(path); if (!buffy) return; diff --git a/color.c b/color.c index 106f45ef2..07789b91a 100644 --- a/color.c +++ b/color.c @@ -340,9 +340,9 @@ int mutt_combine_color(int fg_attr, int bg_attr) void mutt_free_color(int fg, int bg) { - struct ColorList *p = NULL, *q = NULL; + struct ColorList *q = NULL; - p = ColorList; + struct ColorList *p = ColorList; while (p) { if (p->fg == fg && p->bg == bg) diff --git a/commands.c b/commands.c index 41f0ab49c..2c302dca3 100644 --- a/commands.c +++ b/commands.c @@ -661,10 +661,8 @@ void mutt_display_address(struct Envelope *env) { char *pfx = NULL; char buf[SHORT_STRING]; - struct Address *addr = NULL; - - addr = mutt_get_address(env, &pfx); + struct Address *addr = mutt_get_address(env, &pfx); if (!addr) return; @@ -953,15 +951,13 @@ int mutt_edit_content_type(struct Header *h, struct Body *b, FILE *fp) char buf[LONG_STRING]; char obuf[LONG_STRING]; char tmp[STRING]; - char charset[STRING]; - char *cp = NULL; short charset_changed = 0; short type_changed = 0; short structure_changed = 0; - cp = mutt_param_get(&b->parameter, "charset"); + char *cp = mutt_param_get(&b->parameter, "charset"); mutt_str_strfcpy(charset, NONULL(cp), sizeof(charset)); snprintf(buf, sizeof(buf), "%s/%s", TYPE(b), b->subtype); @@ -1050,13 +1046,12 @@ int mutt_edit_content_type(struct Header *h, struct Body *b, FILE *fp) static int check_traditional_pgp(struct Header *h, int *redraw) { - struct Message *msg = NULL; int rc = 0; h->security |= PGP_TRADITIONAL_CHECKED; mutt_parse_mime_message(Context, h); - msg = mx_open_message(Context, h->msgno); + struct Message *msg = mx_open_message(Context, h->msgno); if (!msg) return 0; if (crypt_pgp_check_traditional(msg->fp, h->content, 0)) diff --git a/compose.c b/compose.c index ef5a81a3f..25e6b1a66 100644 --- a/compose.c +++ b/compose.c @@ -776,8 +776,6 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, char helpstr[LONG_STRING]; char buf[LONG_STRING]; char fname[_POSIX_PATH_MAX]; - struct Menu *menu = NULL; - struct AttachCtx *actx = NULL; struct AttachPtr *new = NULL; int i, close = 0; int r = -1; /* return value */ @@ -800,7 +798,7 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, rd.msg = msg; rd.fcc = fcc; - menu = mutt_menu_new(MENU_COMPOSE); + struct Menu *menu = mutt_menu_new(MENU_COMPOSE); menu->offset = HDR_ATTACH; menu->make_entry = snd_entry; menu->tag = mutt_tag_attach; @@ -814,7 +812,7 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, menu->redraw_data = &rd; mutt_menu_push_current(menu); - actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1); + struct AttachCtx *actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1); actx->hdr = msg; mutt_update_compose_menu(actx, menu, 1); @@ -1023,20 +1021,17 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, case OP_COMPOSE_ATTACH_FILE: { - char *prompt = NULL, **files = NULL; - int error, numfiles; - + char *prompt = _("Attach file"); + int numfiles = 0; + char **files = NULL; fname[0] = 0; - prompt = _("Attach file"); - numfiles = 0; - files = NULL; if (mutt_enter_fname_full(prompt, fname, sizeof(fname), 0, 1, &files, &numfiles, MUTT_SEL_MULTI) == -1 || *fname == '\0') break; - error = 0; + int error = 0; if (numfiles > 1) mutt_message(_("Attaching selected files...")); for (i = 0; i < numfiles; i++) @@ -1070,10 +1065,8 @@ int mutt_compose_menu(struct Header *msg, char *fcc, size_t fcclen, case OP_COMPOSE_ATTACH_NEWS_MESSAGE: #endif { - char *prompt = NULL; - + char *prompt = _("Open mailbox to attach message from"); fname[0] = 0; - prompt = _("Open mailbox to attach message from"); #ifdef USE_NNTP OPT_NEWS = false; diff --git a/compress.c b/compress.c index d96fb7f41..c31969b12 100644 --- a/compress.c +++ b/compress.c @@ -149,7 +149,6 @@ static int setup_paths(struct Context *ctx) return -1; char tmppath[_POSIX_PATH_MAX]; - FILE *tmpfp = NULL; /* Setup the right paths */ FREE(&ctx->realpath); @@ -159,7 +158,7 @@ static int setup_paths(struct Context *ctx) mutt_mktemp(tmppath, sizeof(tmppath)); ctx->path = mutt_str_strdup(tmppath); - tmpfp = mutt_file_fopen(ctx->path, "w"); + FILE *tmpfp = mutt_file_fopen(ctx->path, "w"); if (!tmpfp) return -1; diff --git a/conn/sasl.c b/conn/sasl.c index de666c839..083c795d0 100644 --- a/conn/sasl.c +++ b/conn/sasl.c @@ -293,9 +293,7 @@ static int mutt_sasl_cb_pass(sasl_conn_t *conn, void *context, int id, sasl_secr */ static sasl_callback_t *mutt_sasl_get_callbacks(struct Account *account) { - sasl_callback_t *callback = NULL; - - callback = MuttSaslCallbacks; + sasl_callback_t *callback = MuttSaslCallbacks; callback->id = SASL_CB_USER; callback->proc = (int (*)(void)) mutt_sasl_cb_authname; @@ -336,12 +334,9 @@ static sasl_callback_t *mutt_sasl_get_callbacks(struct Account *account) */ static int mutt_sasl_conn_open(struct Connection *conn) { - struct SaslData *sasldata = NULL; - int rc; - - sasldata = (struct SaslData *) conn->sockdata; + struct SaslData *sasldata = (struct SaslData *) conn->sockdata; conn->sockdata = sasldata->sockdata; - rc = (sasldata->msasl_open)(conn); + int rc = (sasldata->msasl_open)(conn); conn->sockdata = sasldata; return rc; @@ -358,10 +353,7 @@ static int mutt_sasl_conn_open(struct Connection *conn) */ static int mutt_sasl_conn_close(struct Connection *conn) { - struct SaslData *sasldata = NULL; - int rc; - - sasldata = (struct SaslData *) conn->sockdata; + struct SaslData *sasldata = (struct SaslData *) conn->sockdata; /* restore connection's underlying methods */ conn->sockdata = sasldata->sockdata; @@ -376,7 +368,7 @@ static int mutt_sasl_conn_close(struct Connection *conn) FREE(&sasldata); /* call underlying close */ - rc = (conn->conn_close)(conn); + int rc = (conn->conn_close)(conn); return rc; } @@ -391,12 +383,10 @@ static int mutt_sasl_conn_close(struct Connection *conn) */ static int mutt_sasl_conn_read(struct Connection *conn, char *buf, size_t len) { - struct SaslData *sasldata = NULL; int rc; - unsigned int olen; - sasldata = (struct SaslData *) conn->sockdata; + struct SaslData *sasldata = (struct SaslData *) conn->sockdata; /* if we still have data in our read buffer, copy it into buf */ if (sasldata->blen > sasldata->bpos) @@ -460,13 +450,11 @@ out: */ static int mutt_sasl_conn_write(struct Connection *conn, const char *buf, size_t len) { - struct SaslData *sasldata = NULL; int rc; - const char *pbuf = NULL; unsigned int olen, plen; - sasldata = (struct SaslData *) conn->sockdata; + struct SaslData *sasldata = (struct SaslData *) conn->sockdata; conn->sockdata = sasldata->sockdata; /* encode data, if necessary */ diff --git a/conn/socket.c b/conn/socket.c index 00f0a5a03..bb368785c 100644 --- a/conn/socket.c +++ b/conn/socket.c @@ -314,9 +314,7 @@ int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int */ struct Connection *socket_new_conn(void) { - struct Connection *conn = NULL; - - conn = mutt_mem_calloc(1, sizeof(struct Connection)); + struct Connection *conn = mutt_mem_calloc(1, sizeof(struct Connection)); conn->fd = -1; return conn; diff --git a/conn/ssl_gnutls.c b/conn/ssl_gnutls.c index 8521d1c55..bb7ab03ed 100644 --- a/conn/ssl_gnutls.c +++ b/conn/ssl_gnutls.c @@ -288,15 +288,14 @@ static void tls_fingerprint(gnutls_digest_algorithm_t algo, char *s, int l, */ static int tls_check_stored_hostname(const gnutls_datum_t *cert, const char *hostname) { - FILE *fp = NULL; char *linestr = NULL; - size_t linestrsize; + size_t linestrsize = 0; int linenum = 0; regex_t preg; regmatch_t pmatch[3]; /* try checking against names stored in stored certs file */ - fp = fopen(CertificateFile, "r"); + FILE *fp = fopen(CertificateFile, "r"); if (fp) { if (REGCOMP(&preg, "^#H ([a-zA-Z0-9_\\.-]+) ([0-9A-F]{4}( [0-9A-F]{4}){7})[ \t]*$", @@ -944,7 +943,6 @@ static int tls_check_certificate(struct Connection *conn) static void tls_get_client_cert(struct Connection *conn) { struct TlsSockData *data = conn->sockdata; - const gnutls_datum_t *crtdata = NULL; gnutls_x509_crt_t clientcrt; char *dn = NULL; char *cn = NULL; @@ -952,7 +950,7 @@ static void tls_get_client_cert(struct Connection *conn) size_t dnlen; /* get our cert CN if we have one */ - crtdata = gnutls_certificate_get_ours(data->state); + const gnutls_datum_t *crtdata = gnutls_certificate_get_ours(data->state); if (!crtdata) return; @@ -1006,12 +1004,10 @@ err_crt: static int tls_set_priority(struct TlsSockData *data) { size_t nproto = 4; - char *priority = NULL; size_t priority_size; - int err; priority_size = SHORT_STRING + mutt_str_strlen(SslCiphers); - priority = mutt_mem_malloc(priority_size); + char *priority = mutt_mem_malloc(priority_size); priority[0] = 0; if (SslCiphers) @@ -1047,7 +1043,7 @@ static int tls_set_priority(struct TlsSockData *data) return -1; } - err = gnutls_priority_set_direct(data->state, priority, NULL); + int err = gnutls_priority_set_direct(data->state, priority, NULL); if (err < 0) { mutt_error("gnutls_priority_set_direct(%s): %s", priority, gnutls_strerror(err)); @@ -1111,12 +1107,9 @@ static int tls_set_priority(struct TlsSockData *data) */ static int tls_negotiate(struct Connection *conn) { - struct TlsSockData *data = NULL; - int err; - - data = mutt_mem_calloc(1, sizeof(struct TlsSockData)); + struct TlsSockData *data = mutt_mem_calloc(1, sizeof(struct TlsSockData)); conn->sockdata = data; - err = gnutls_certificate_allocate_credentials(&data->xcred); + int err = gnutls_certificate_allocate_credentials(&data->xcred); if (err < 0) { FREE(&conn->sockdata); diff --git a/conn/tunnel.c b/conn/tunnel.c index d1fd987e7..076532382 100644 --- a/conn/tunnel.c +++ b/conn/tunnel.c @@ -61,17 +61,14 @@ struct TunnelData */ static int tunnel_socket_open(struct Connection *conn) { - struct TunnelData *tunnel = NULL; - int pid; - int rc; int pin[2], pout[2]; - tunnel = mutt_mem_malloc(sizeof(struct TunnelData)); + struct TunnelData *tunnel = mutt_mem_malloc(sizeof(struct TunnelData)); conn->sockdata = tunnel; mutt_message(_("Connecting with \"%s\"..."), Tunnel); - rc = pipe(pin); + int rc = pipe(pin); if (rc == -1) { mutt_perror("pipe"); @@ -89,7 +86,7 @@ static int tunnel_socket_open(struct Connection *conn) } mutt_sig_block_system(); - pid = fork(); + int pid = fork(); if (pid == 0) { mutt_sig_unblock_system(0); diff --git a/copy.c b/copy.c index ab5487c51..e96708d6c 100644 --- a/copy.c +++ b/copy.c @@ -751,15 +751,12 @@ int mutt_copy_message_fp(FILE *fpout, FILE *fpin, struct Header *hdr, int flags, int mutt_copy_message_ctx(FILE *fpout, struct Context *src, struct Header *hdr, int flags, int chflags) { - struct Message *msg = NULL; - int r; - - msg = mx_open_message(src, hdr->msgno); + struct Message *msg = mx_open_message(src, hdr->msgno); if (!msg) return -1; if (!hdr->content) return -1; - r = mutt_copy_message_fp(fpout, msg->fp, hdr, flags, chflags); + int r = mutt_copy_message_fp(fpout, msg->fp, hdr, flags, chflags); if ((r == 0) && (ferror(fpout) || feof(fpout))) { mutt_debug(1, "failed to detect EOF!\n"); @@ -814,13 +811,10 @@ static int append_message(struct Context *dest, FILE *fpin, struct Context *src, int mutt_append_message(struct Context *dest, struct Context *src, struct Header *hdr, int cmflags, int chflags) { - struct Message *msg = NULL; - int r; - - msg = mx_open_message(src, hdr->msgno); + struct Message *msg = mx_open_message(src, hdr->msgno); if (!msg) return -1; - r = append_message(dest, msg->fp, src, hdr, cmflags, chflags); + int r = append_message(dest, msg->fp, src, hdr, cmflags, chflags); mx_close_message(src, &msg); return r; } diff --git a/curs_lib.c b/curs_lib.c index c1afd7b1f..d49a8ea0a 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -734,7 +734,6 @@ int mutt_addwch(wchar_t wc) void mutt_simple_format(char *buf, size_t buflen, int min_width, int max_width, int justify, char pad_char, const char *s, size_t n, int arboreal) { - char *p = NULL; wchar_t wc; int w; size_t k, k2; @@ -745,7 +744,7 @@ void mutt_simple_format(char *buf, size_t buflen, int min_width, int max_width, memset(&mbstate1, 0, sizeof(mbstate1)); memset(&mbstate2, 0, sizeof(mbstate2)); buflen--; - p = buf; + char *p = buf; for (; n && (k = mbrtowc(&wc, s, n, &mbstate1)); s += k, n -= k) { if (k == (size_t)(-1) || k == (size_t)(-2)) diff --git a/curs_main.c b/curs_main.c index 3a5b74ad6..c8e571164 100644 --- a/curs_main.c +++ b/curs_main.c @@ -446,7 +446,6 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, if (Context) { - int check; char *new_last_folder = NULL; #ifdef USE_COMPRESSED @@ -457,7 +456,7 @@ static int main_change_folder(struct Menu *menu, int op, char *buf, new_last_folder = mutt_str_strdup(Context->path); *oldcount = Context ? Context->msgcount : 0; - check = mx_close_mailbox(Context, index_hint); + int check = mx_close_mailbox(Context, index_hint); if (check != 0) { if (check == MUTT_NEW_MAIL || check == MUTT_REOPENED) @@ -833,14 +832,13 @@ int mutt_index_menu(void) int newcount = -1; int oldcount = -1; int rc = -1; - struct Menu *menu = NULL; char *cp = NULL; /* temporary variable. */ int index_hint; /* used to restore cursor position */ bool do_buffy_notify = true; int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */ int attach_msg = OPT_ATTACH_MSG; - menu = mutt_menu_new(MENU_MAIN); + struct Menu *menu = mutt_menu_new(MENU_MAIN); menu->make_entry = index_make_entry; menu->color = index_color; menu->current = ci_first_message(); diff --git a/edit.c b/edit.c index b6a878c5f..6178082ab 100644 --- a/edit.c +++ b/edit.c @@ -105,11 +105,10 @@ static char **be_snarf_data(FILE *f, char **buf, int *bufmax, int *buflen, static char **be_snarf_file(const char *path, char **buf, int *max, int *len, int verbose) { - FILE *f = NULL; char tmp[LONG_STRING]; struct stat sb; - f = fopen(path, "r"); + FILE *f = fopen(path, "r"); if (f) { fstat(fileno(f), &sb); @@ -131,9 +130,7 @@ static char **be_snarf_file(const char *path, char **buf, int *max, int *len, in static int be_barf_file(const char *path, char **buf, int buflen) { - FILE *f = NULL; - - f = fopen(path, "w"); + FILE *f = fopen(path, "w"); if (!f) { addstr(strerror(errno)); diff --git a/handler.c b/handler.c index 3282f4afe..7c51d91a0 100644 --- a/handler.c +++ b/handler.c @@ -906,10 +906,9 @@ static int text_enriched_handler(struct Body *a, struct State *s) static int is_mmnoask(const char *buf) { char *p = NULL; - const char *val = NULL; char tmp[LONG_STRING], *q = NULL; - val = mutt_str_getenv("MM_NOASK"); + const char *val = mutt_str_getenv("MM_NOASK"); if (val) { if (mutt_str_strcmp(val, "1") == 0) @@ -1027,11 +1026,10 @@ static int alternative_handler(struct Body *a, struct State *s) struct ListNode *np; STAILQ_FOREACH(np, &AlternativeOrderList, entries) { - char *c = NULL; int btlen; /* length of basetype */ bool wild; /* do we have a wildcard to match all subtypes? */ - c = strchr(np->data, '/'); + char *c = strchr(np->data, '/'); if (c) { wild = (c[1] == '*' && c[2] == 0); @@ -1466,11 +1464,7 @@ static int autoview_handler(struct Body *a, struct State *s) static int external_body_handler(struct Body *b, struct State *s) { - const char *access_type = NULL; - const char *expiration = NULL; - time_t expire; - - access_type = mutt_param_get(&b->parameter, "access-type"); + const char *access_type = mutt_param_get(&b->parameter, "access-type"); if (!access_type) { if (s->flags & MUTT_DISPLAY) @@ -1485,7 +1479,8 @@ static int external_body_handler(struct Body *b, struct State *s) return -1; } - expiration = mutt_param_get(&b->parameter, "expiration"); + const char *expiration = mutt_param_get(&b->parameter, "expiration"); + time_t expire; if (expiration) expire = mutt_date_parse_date(expiration, NULL); else @@ -1774,11 +1769,8 @@ static int run_decode_and_handler(struct Body *b, struct State *s, static int valid_pgp_encrypted_handler(struct Body *b, struct State *s) { - int rc; - struct Body *octetstream = NULL; - - octetstream = b->parts->next; - rc = crypt_pgp_encrypted_handler(octetstream, s); + struct Body *octetstream = b->parts->next; + int rc = crypt_pgp_encrypted_handler(octetstream, s); b->goodsig |= octetstream->goodsig; return rc; @@ -1786,12 +1778,9 @@ static int valid_pgp_encrypted_handler(struct Body *b, struct State *s) static int malformed_pgp_encrypted_handler(struct Body *b, struct State *s) { - int rc; - struct Body *octetstream = NULL; - - octetstream = b->parts->next->next; + struct Body *octetstream = b->parts->next->next; /* exchange encodes the octet-stream, so re-run it through the decoder */ - rc = run_decode_and_handler(octetstream, s, crypt_pgp_encrypted_handler, 0); + int rc = run_decode_and_handler(octetstream, s, crypt_pgp_encrypted_handler, 0); b->goodsig |= octetstream->goodsig; return rc; diff --git a/hcache/hcache.c b/hcache/hcache.c index ff8929074..8302f4cd3 100644 --- a/hcache/hcache.c +++ b/hcache/hcache.c @@ -627,12 +627,11 @@ static const char *hcache_per_folder(const char *path, const char *folder, hcach static void *hcache_dump(header_cache_t *h, struct Header *header, int *off, unsigned int uidvalidity) { - unsigned char *d = NULL; struct Header nh; bool convert = !CharsetIsUtf8; *off = 0; - d = lazy_malloc(sizeof(union Validate)); + unsigned char *d = lazy_malloc(sizeof(union Validate)); if (uidvalidity == 0) { @@ -711,11 +710,9 @@ struct Header *mutt_hcache_restore(const unsigned char *d) static char *get_foldername(const char *folder) { - char *p = NULL; - /* if the folder is local, canonify the path to avoid * to ensure equivalent paths share the hcache */ - p = mutt_mem_malloc(PATH_MAX + 1); + char *p = mutt_mem_malloc(PATH_MAX + 1); if (!realpath(folder, p)) mutt_str_replace(&p, folder); @@ -810,9 +807,7 @@ void mutt_hcache_close(header_cache_t *h) void *mutt_hcache_fetch(header_cache_t *h, const char *key, size_t keylen) { - void *data = NULL; - - data = mutt_hcache_fetch_raw(h, key, keylen); + void *data = mutt_hcache_fetch_raw(h, key, keylen); if (!data) { return NULL; diff --git a/hdrline.c b/hdrline.c index b15fe75ab..6994b2867 100644 --- a/hdrline.c +++ b/hdrline.c @@ -479,8 +479,6 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co unsigned long data, enum FormatFlag flags) { struct HdrFormatInfo *hfi = (struct HdrFormatInfo *) data; - struct Header *hdr = NULL, *htmp = NULL; - struct Context *ctx = NULL; char fmt[SHORT_STRING], tmp[LONG_STRING], *p, *tags = NULL; char *wch = NULL; int i; @@ -489,8 +487,8 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co int is_index = (flags & MUTT_FORMAT_INDEX); size_t colorlen; - hdr = hfi->hdr; - ctx = hfi->ctx; + struct Header *hdr = hfi->hdr; + struct Context *ctx = hfi->ctx; if (!hdr || !hdr->env) return src; @@ -1184,7 +1182,7 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co if (hdr->env->x_label) { i = 1; /* reduce reuse recycle */ - htmp = NULL; + struct Header *htmp = NULL; if (flags & MUTT_FORMAT_TREE && (hdr->thread->prev && hdr->thread->prev->message && hdr->thread->prev->message->env->x_label)) { diff --git a/header.c b/header.c index 6ac9a7698..92065b6e6 100644 --- a/header.c +++ b/header.c @@ -45,14 +45,13 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */ char buffer[LONG_STRING]; const char *p = NULL; - FILE *ifp = NULL, *ofp = NULL; int i; struct Envelope *n = NULL; time_t mtime; struct stat st; mutt_mktemp(path, sizeof(path)); - ofp = mutt_file_fopen(path, "w"); + FILE *ofp = mutt_file_fopen(path, "w"); if (!ofp) { mutt_perror(path); @@ -64,7 +63,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, fputc('\n', ofp); /* tie off the header. */ /* now copy the body of the message. */ - ifp = fopen(body, "r"); + FILE *ifp = fopen(body, "r"); if (!ifp) { mutt_perror(body); @@ -224,14 +223,11 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, static void label_ref_dec(struct Context *ctx, char *label) { - struct HashElem *elem = NULL; - uintptr_t count; - - elem = mutt_hash_find_elem(ctx->label_hash, label); + struct HashElem *elem = mutt_hash_find_elem(ctx->label_hash, label); if (!elem) return; - count = (uintptr_t) elem->data; + uintptr_t count = (uintptr_t) elem->data; if (count <= 1) { mutt_hash_delete(ctx->label_hash, label, NULL); @@ -244,10 +240,9 @@ static void label_ref_dec(struct Context *ctx, char *label) static void label_ref_inc(struct Context *ctx, char *label) { - struct HashElem *elem = NULL; uintptr_t count; - elem = mutt_hash_find_elem(ctx->label_hash, label); + struct HashElem *elem = mutt_hash_find_elem(ctx->label_hash, label); if (!elem) { count = 1; diff --git a/help.c b/help.c index e7d47173e..3a98062a3 100644 --- a/help.c +++ b/help.c @@ -347,14 +347,12 @@ void mutt_help(int menu) { char t[_POSIX_PATH_MAX]; char buf[SHORT_STRING]; - const char *desc = NULL; FILE *f = NULL; - const struct Binding *funcs = NULL; mutt_mktemp(t, sizeof(t)); - funcs = km_get_table(menu); - desc = mutt_map_get_name(menu, Menus); + const struct Binding *funcs = km_get_table(menu); + const char *desc = mutt_map_get_name(menu, Menus); if (!desc) desc = _(""); diff --git a/history.c b/history.c index b64d423ab..01f9eb2c5 100644 --- a/history.c +++ b/history.c @@ -167,14 +167,11 @@ static void init_history(struct History *h) */ static int dup_hash_dec(struct Hash *dup_hash, char *str) { - struct HashElem *elem = NULL; - uintptr_t count; - - elem = mutt_hash_find_elem(dup_hash, str); + struct HashElem *elem = mutt_hash_find_elem(dup_hash, str); if (!elem) return -1; - count = (uintptr_t) elem->data; + uintptr_t count = (uintptr_t) elem->data; if (count <= 1) { mutt_hash_delete(dup_hash, str, NULL); @@ -196,10 +193,9 @@ static int dup_hash_dec(struct Hash *dup_hash, char *str) */ static int dup_hash_inc(struct Hash *dup_hash, char *str) { - struct HashElem *elem = NULL; uintptr_t count; - elem = mutt_hash_find_elem(dup_hash, str); + struct HashElem *elem = mutt_hash_find_elem(dup_hash, str); if (!elem) { count = 1; @@ -219,7 +215,7 @@ static int dup_hash_inc(struct Hash *dup_hash, char *str) static void shrink_histfile(void) { char tmpfname[_POSIX_PATH_MAX]; - FILE *f = NULL, *tmp = NULL; + FILE *tmp = NULL; int n[HC_LAST] = { 0 }; int line, hclass, read; char *linebuf = NULL, *p = NULL; @@ -227,7 +223,7 @@ static void shrink_histfile(void) bool regen_file = false; struct Hash *dup_hashes[HC_LAST] = { 0 }; - f = fopen(HistoryFile, "r"); + FILE *f = fopen(HistoryFile, "r"); if (!f) return; @@ -552,12 +548,11 @@ void mutt_hist_reset_state(enum HistoryClass hclass) */ void mutt_hist_read_file(void) { - FILE *f = NULL; int line = 0, hclass, read; char *linebuf = NULL, *p = NULL; size_t buflen; - f = fopen(HistoryFile, "r"); + FILE *f = fopen(HistoryFile, "r"); if (!f) return; diff --git a/imap/command.c b/imap/command.c index 970d63185..1e286b9b6 100644 --- a/imap/command.c +++ b/imap/command.c @@ -361,12 +361,10 @@ static void cmd_parse_fetch(struct ImapData *idata, char *s) */ static void cmd_parse_capability(struct ImapData *idata, char *s) { - char *bracket = NULL; - mutt_debug(3, "Handling CAPABILITY\n"); s = imap_next_word(s); - bracket = strchr(s, ']'); + char *bracket = strchr(s, ']'); if (bracket) *bracket = '\0'; FREE(&idata->capstr); @@ -618,7 +616,6 @@ static void cmd_parse_search(struct ImapData *idata, const char *s) */ static void cmd_parse_status(struct ImapData *idata, char *s) { - char *mailbox = NULL; char *value = NULL; struct Buffy *inc = NULL; struct ImapMbox mx; @@ -628,7 +625,7 @@ static void cmd_parse_status(struct ImapData *idata, char *s) short new = 0; short new_msg_count = 0; - mailbox = imap_next_word(s); + char *mailbox = imap_next_word(s); /* We need a real tokenizer. */ if (imap_get_literal_count(mailbox, &litlen) == 0) @@ -805,12 +802,9 @@ static void cmd_parse_enabled(struct ImapData *idata, const char *s) */ static int cmd_handle_untagged(struct ImapData *idata) { - char *s = NULL; - char *pn = NULL; unsigned int count = 0; - - s = imap_next_word(idata->buf); - pn = imap_next_word(s); + char *s = imap_next_word(idata->buf); + char *pn = imap_next_word(s); if ((idata->state >= IMAP_SELECTED) && isdigit((unsigned char) *s)) { diff --git a/imap/imap.c b/imap/imap.c index a7415cde7..93f62a1bb 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1175,12 +1175,11 @@ int imap_exec_msgset(struct ImapData *idata, const char *pre, const char *post, { struct Header **hdrs = NULL; short oldsort; - struct Buffer *cmd = NULL; int pos; int rc; int count = 0; - cmd = mutt_buffer_new(); + struct Buffer *cmd = mutt_buffer_new(); if (!cmd) { mutt_debug(1, "unable to allocate buffer\n"); @@ -1870,7 +1869,6 @@ int imap_complete(char *dest, size_t dlen, char *path) */ int imap_fast_trash(struct Context *ctx, char *dest) { - struct ImapData *idata = NULL; char mbox[LONG_STRING]; char mmbox[LONG_STRING]; char prompt[LONG_STRING]; @@ -1880,7 +1878,7 @@ int imap_fast_trash(struct Context *ctx, char *dest) struct Buffer *sync_cmd = NULL; int err_continue = MUTT_NO; - idata = ctx->data; + struct ImapData *idata = ctx->data; if (imap_parse_path(dest, &mx)) { @@ -2131,9 +2129,8 @@ static int imap_open_mailbox(struct Context *ctx) if (rc == IMAP_CMD_NO) { - char *s = NULL; - s = imap_next_word(idata->buf); /* skip seq */ - s = imap_next_word(s); /* Skip response */ + char *s = imap_next_word(idata->buf); /* skip seq */ + s = imap_next_word(s); /* Skip response */ mutt_error("%s", s); goto fail; } @@ -2257,9 +2254,7 @@ static int imap_open_mailbox_append(struct Context *ctx, int flags) */ static int imap_close_mailbox(struct Context *ctx) { - struct ImapData *idata = NULL; - - idata = ctx->data; + struct ImapData *idata = ctx->data; /* Check to see if the mailbox is actually open */ if (!idata) return 0; @@ -2367,14 +2362,13 @@ static int imap_check_mailbox_reopen(struct Context *ctx, int *index_hint) */ int imap_sync_mailbox(struct Context *ctx, int expunge) { - struct ImapData *idata = NULL; struct Context *appendctx = NULL; struct Header *h = NULL; struct Header **hdrs = NULL; int oldsort; int rc; - idata = ctx->data; + struct ImapData *idata = ctx->data; if (idata->state < IMAP_SELECTED) { @@ -2660,11 +2654,10 @@ static int imap_edit_message_tags(struct Context *ctx, const char *tags, char *b */ static int imap_commit_message_tags(struct Context *ctx, struct Header *h, char *tags) { - struct ImapData *idata = NULL; struct Buffer *cmd = NULL; char uid[11]; - idata = ctx->data; + struct ImapData *idata = ctx->data; if (*tags == '\0') tags = NULL; diff --git a/imap/message.c b/imap/message.c index f8b0cc32a..5faa8cf40 100644 --- a/imap/message.c +++ b/imap/message.c @@ -78,10 +78,9 @@ static struct ImapHeaderData *new_header_data(void) */ static void update_context(struct ImapData *idata, int oldmsgcount) { - struct Context *ctx = NULL; struct Header *h = NULL; - ctx = idata->ctx; + struct Context *ctx = idata->ctx; if (!idata->uid_hash) idata->uid_hash = mutt_hash_int_create(MAX(6 * ctx->msgcount / 5, 30), 0); @@ -386,12 +385,11 @@ static int msg_parse_fetch(struct ImapHeader *h, char *s) */ static int msg_fetch_header(struct Context *ctx, struct ImapHeader *h, char *buf, FILE *fp) { - struct ImapData *idata = NULL; unsigned int bytes; int rc = -1; /* default now is that string isn't FETCH response */ int parse_rc; - idata = ctx->data; + struct ImapData *idata = ctx->data; if (buf[0] != '*') return rc; @@ -609,7 +607,6 @@ static void set_changed_flag(struct Context *ctx, struct Header *h, */ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned int msn_end) { - struct Context *ctx = NULL; char *hdrreq = NULL; FILE *fp = NULL; char tempfile[_POSIX_PATH_MAX]; @@ -634,7 +631,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i unsigned int uidnext = 0; #endif /* USE_HCACHE */ - ctx = idata->ctx; + struct Context *ctx = idata->ctx; if (mutt_bit_isset(idata->capabilities, IMAP4REV1)) { @@ -793,10 +790,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i while (msn_begin <= msn_end && fetch_msn_end < msn_end) { - char *cmd = NULL; - struct Buffer *b = NULL; - - b = mutt_buffer_new(); + struct Buffer *b = mutt_buffer_new(); if (evalhc) { /* In case there are holes in the header cache. */ @@ -807,6 +801,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i mutt_buffer_printf(b, "%u:%u", msn_begin, msn_end); fetch_msn_end = msn_end; + char *cmd = NULL; safe_asprintf(&cmd, "FETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE %s)", b->data, hdrreq); imap_cmd_start(idata, cmd); FREE(&cmd); @@ -985,8 +980,6 @@ error_out_0: */ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) { - struct ImapData *idata = NULL; - struct Header *h = NULL; struct Envelope *newenv = NULL; char buf[LONG_STRING]; char path[_POSIX_PATH_MAX]; @@ -1004,8 +997,8 @@ int imap_fetch_message(struct Context *ctx, struct Message *msg, int msgno) bool fetched = false; int output_progress; - idata = ctx->data; - h = ctx->hdrs[msgno]; + struct ImapData *idata = ctx->data; + struct Header *h = ctx->hdrs[msgno]; msg->fp = msg_cache_get(idata, h); if (msg->fp) @@ -1238,7 +1231,6 @@ int imap_commit_message(struct Context *ctx, struct Message *msg) */ int imap_append_message(struct Context *ctx, struct Message *msg) { - struct ImapData *idata = NULL; FILE *fp = NULL; char buf[LONG_STRING]; char mbox[LONG_STRING]; @@ -1252,7 +1244,7 @@ int imap_append_message(struct Context *ctx, struct Message *msg) struct ImapMbox mx; int rc; - idata = ctx->data; + struct ImapData *idata = ctx->data; if (imap_parse_path(ctx->path, &mx)) return -1; @@ -1310,11 +1302,9 @@ int imap_append_message(struct Context *ctx, struct Message *msg) if (rc != IMAP_CMD_RESPOND) { - char *pc = NULL; - mutt_debug(1, "#1 command failed: %s\n", idata->buf); - pc = idata->buf + SEQLEN; + char *pc = idata->buf + SEQLEN; SKIPWS(pc); pc = imap_next_word(pc); mutt_error("%s", pc); @@ -1349,10 +1339,8 @@ int imap_append_message(struct Context *ctx, struct Message *msg) if (!imap_code(idata->buf)) { - char *pc = NULL; - mutt_debug(1, "#2 command failed: %s\n", idata->buf); - pc = idata->buf + SEQLEN; + char *pc = idata->buf + SEQLEN; SKIPWS(pc); pc = imap_next_word(pc); mutt_error("%s", pc); @@ -1379,7 +1367,6 @@ fail: */ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int delete) { - struct ImapData *idata = NULL; struct Buffer cmd, sync_cmd; char mbox[LONG_STRING]; char mmbox[LONG_STRING]; @@ -1389,7 +1376,7 @@ int imap_copy_messages(struct Context *ctx, struct Header *h, char *dest, int de int err_continue = MUTT_NO; int triedcreate = 0; - idata = ctx->data; + struct ImapData *idata = ctx->data; if (imap_parse_path(dest, &mx)) { @@ -1624,14 +1611,13 @@ char *imap_set_flags(struct ImapData *idata, struct Header *h, char *s, int *ser struct Context *ctx = idata->ctx; struct ImapHeader newh; struct ImapHeaderData old_hd; - struct ImapHeaderData *hd = NULL; bool readonly; int local_changes; local_changes = h->changed; memset(&newh, 0, sizeof(newh)); - hd = h->data; + struct ImapHeaderData *hd = h->data; newh.data = hd; memcpy(&old_hd, hd, sizeof(old_hd)); diff --git a/imap/utf7.c b/imap/utf7.c index a58675878..7c3bfa9b9 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -82,10 +82,10 @@ static const char B64Chars[64] = { */ static char *utf7_to_utf8(const char *u7, size_t u7len, char **u8, size_t *u8len) { - char *buf = NULL, *p = NULL; int b, ch, k; - p = buf = mutt_mem_malloc(u7len + u7len / 8 + 1); + char *buf = mutt_mem_malloc(u7len + u7len / 8 + 1); + char *p = buf; for (; u7len; u7++, u7len--) { @@ -192,7 +192,6 @@ bail: */ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len) { - char *buf = NULL, *p = NULL; int ch; int n, b = 0, k = 0; bool base64 = false; @@ -201,7 +200,8 @@ static char *utf8_to_utf7(const char *u8, size_t u8len, char **u7, size_t *u7len * In the worst case we convert 2 chars to 7 chars. For example: * "\x10&\x10&..." -> "&ABA-&-&ABA-&-...". */ - p = buf = mutt_mem_malloc((u8len / 2) * 7 + 6); + char *buf = mutt_mem_malloc((u8len / 2) * 7 + 6); + char *p = buf; while (u8len) { diff --git a/imap/util.c b/imap/util.c index 62b98db7f..d53d0f8f6 100644 --- a/imap/util.c +++ b/imap/util.c @@ -800,11 +800,8 @@ void imap_qualify_path(char *dest, size_t len, struct ImapMbox *mx, char *path) void imap_quote_string(char *dest, size_t dlen, const char *src) { static const char quote[] = "\"\\"; - char *pt = NULL; - const char *s = NULL; - - pt = dest; - s = src; + char *pt = dest; + const char *s = src; *pt++ = '"'; /* save room for trailing quote-char */ @@ -873,9 +870,7 @@ void imap_unquote_string(char *s) */ void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const char *src) { - char *buf = NULL; - - buf = mutt_str_strdup(src); + char *buf = mutt_str_strdup(src); imap_utf_encode(idata, &buf); imap_quote_string(dest, dlen, buf); @@ -892,11 +887,9 @@ void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const */ void imap_unmunge_mbox_name(struct ImapData *idata, char *s) { - char *buf = NULL; - imap_unquote_string(s); - buf = mutt_str_strdup(s); + char *buf = mutt_str_strdup(s); if (buf) { imap_utf_decode(idata, &buf); diff --git a/init.c b/init.c index d83f16373..ca00edac2 100644 --- a/init.c +++ b/init.c @@ -275,12 +275,11 @@ static void free_mbtable(struct MbTable **t) static struct MbTable *parse_mbtable(const char *s) { - struct MbTable *t = NULL; size_t slen, k; mbstate_t mbstate; char *d = NULL; - t = mutt_mem_calloc(1, sizeof(struct MbTable)); + struct MbTable *t = mutt_mem_calloc(1, sizeof(struct MbTable)); slen = mutt_str_strlen(s); if (slen == 0) return t; @@ -1813,10 +1812,9 @@ static int parse_my_hdr(struct Buffer *buf, struct Buffer *s, { struct ListNode *n = NULL; size_t keylen; - char *p = NULL; mutt_extract_token(buf, s, MUTT_TOKEN_SPACE | MUTT_TOKEN_QUOTE); - p = strpbrk(buf->data, ": \t"); + char *p = strpbrk(buf->data, ": \t"); if (!p || (*p != ':')) { mutt_str_strfcpy(err->data, _("invalid header field"), err->dsize); @@ -3724,7 +3722,6 @@ static bool get_hostname(void) int mutt_init(int skip_sys_rc, struct ListHead *commands) { - const char *p = NULL; char buffer[LONG_STRING]; int need_pause = 0; struct Buffer err; @@ -3746,7 +3743,7 @@ int mutt_init(int skip_sys_rc, struct ListHead *commands) snprintf(AttachmentMarker, sizeof(AttachmentMarker), "\033]9;%" PRIu64 "\a", mutt_rand64()); - p = mutt_str_getenv("MAIL"); + const char *p = mutt_str_getenv("MAIL"); if (p) SpoolFile = mutt_str_strdup(p); else if ((p = mutt_str_getenv("MAILDIR"))) diff --git a/keymap.c b/keymap.c index 02fde9215..d7c4de201 100644 --- a/keymap.c +++ b/keymap.c @@ -134,9 +134,7 @@ struct Keymap *Keymaps[MENU_MAX]; static struct Keymap *alloc_keys(size_t len, keycode_t *keys) { - struct Keymap *p = NULL; - - p = mutt_mem_calloc(1, sizeof(struct Keymap)); + struct Keymap *p = mutt_mem_calloc(1, sizeof(struct Keymap)); p->len = len; p->keys = mutt_mem_malloc(len * sizeof(keycode_t)); memcpy(p->keys, keys, len * sizeof(keycode_t)); @@ -191,10 +189,10 @@ static size_t parsekeys(const char *str, keycode_t *d, size_t max) size_t len = max; char buf[SHORT_STRING]; char c; - char *s = NULL, *t = NULL; + char *t = NULL; mutt_str_strfcpy(buf, str, sizeof(buf)); - s = buf; + char *s = buf; while (*s && len) { @@ -246,19 +244,18 @@ static size_t parsekeys(const char *str, keycode_t *d, size_t max) int km_bind_err(char *s, int menu, int op, char *macro, char *descr, struct Buffer *err) { int retval = 0; - struct Keymap *map = NULL, *tmp = NULL, *last = NULL, *next = NULL; + struct Keymap *last = NULL, *next = NULL; keycode_t buf[MAX_SEQ]; - size_t len; size_t pos = 0, lastpos = 0; - len = parsekeys(s, buf, MAX_SEQ); + size_t len = parsekeys(s, buf, MAX_SEQ); - map = alloc_keys(len, buf); + struct Keymap *map = alloc_keys(len, buf); map->op = op; map->macro = mutt_str_strdup(macro); map->descr = mutt_str_strdup(descr); - tmp = Keymaps[menu]; + struct Keymap *tmp = Keymaps[menu]; while (tmp) { @@ -481,14 +478,13 @@ int km_dokey(int menu) struct Keymap *map = Keymaps[menu]; int pos = 0; int n = 0; - int i; if (!map) return (retry_generic(menu, NULL, 0, 0)); while (true) { - i = Timeout > 0 ? Timeout : 60; + int i = Timeout > 0 ? Timeout : 60; #ifdef USE_IMAP /* keepalive may need to run more frequently than Timeout allows */ if (ImapKeepalive) @@ -622,9 +618,8 @@ static void create_bindings(const struct Binding *map, int menu) static const char *km_keyname(int c) { static char buf[10]; - const char *p = NULL; - p = mutt_map_get_name(c, KeyNames); + const char *p = mutt_map_get_name(c, KeyNames); if (p) return p; @@ -905,10 +900,9 @@ void km_init(void) void km_error_key(int menu) { char buf[SHORT_STRING]; - struct Keymap *key = NULL; int p, op; - key = km_find_func(menu, OP_HELP); + struct Keymap *key = km_find_func(menu, OP_HELP); if (!key && (menu != MENU_EDITOR) && (menu != MENU_PAGER)) key = km_find_func(MENU_GENERIC, OP_HELP); if (!key) @@ -983,13 +977,13 @@ static char *parse_keymap(int *menu, struct Buffer *s, int maxmenus, { struct Buffer buf; int i = 0; - char *p = NULL, *q = NULL; + char *q = NULL; mutt_buffer_init(&buf); /* menu name */ mutt_extract_token(&buf, s, 0); - p = buf.data; + char *p = buf.data; if (MoreArgs(s)) { while (i < maxmenus) @@ -1097,10 +1091,9 @@ int mutt_parse_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { const struct Binding *bindings = NULL; - char *key = NULL; int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], r = 0, nummenus; - key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true); + char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, true); if (!key) return -1; @@ -1156,9 +1149,8 @@ int mutt_parse_macro(struct Buffer *buf, struct Buffer *s, unsigned long data, { int menu[sizeof(Menus) / sizeof(struct Mapping) - 1], r = -1, nummenus; char *seq = NULL; - char *key = NULL; - key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, false); + char *key = parse_keymap(menu, s, mutt_array_size(menu), &nummenus, err, false); if (!key) return -1; diff --git a/main.c b/main.c index 34e1efa09..ddc6b8a5d 100644 --- a/main.c +++ b/main.c @@ -176,9 +176,7 @@ static int start_curses(void) static int get_user_info(void) { - const char *p = NULL; - - p = mutt_str_getenv("HOME"); + const char *p = mutt_str_getenv("HOME"); if (p) HomeDir = mutt_str_strdup(p); @@ -795,7 +793,6 @@ int main(int argc, char *argv[], char *envp[]) */ if (draft_file) { - struct Header *context_hdr = NULL; struct Envelope *opts_env = msg->env; struct stat st; @@ -804,7 +801,7 @@ int main(int argc, char *argv[], char *envp[]) /* Set up a "context" header with just enough information so that * mutt_prepare_template() can parse the message in fin. */ - context_hdr = mutt_header_new(); + struct Header *context_hdr = mutt_header_new(); context_hdr->offset = 0; context_hdr->content = mutt_body_new(); if (fstat(fileno(fin), &st) != 0) diff --git a/menu.c b/menu.c index 97311db5f..84b6e13e4 100644 --- a/menu.c +++ b/menu.c @@ -879,18 +879,14 @@ void mutt_menu_pop_current(struct Menu *menu) void mutt_menu_set_current_redraw(int redraw) { - struct Menu *current_menu = NULL; - - current_menu = get_current_menu(); + struct Menu *current_menu = get_current_menu(); if (current_menu) current_menu->redraw |= redraw; } void mutt_menu_set_current_redraw_full(void) { - struct Menu *current_menu = NULL; - - current_menu = get_current_menu(); + struct Menu *current_menu = get_current_menu(); if (current_menu) current_menu->redraw = REDRAW_FULL; } @@ -909,9 +905,7 @@ void mutt_menu_set_redraw_full(int menu_type) void mutt_menu_current_redraw() { - struct Menu *current_menu = NULL; - - current_menu = get_current_menu(); + struct Menu *current_menu = get_current_menu(); if (current_menu) { if (menu_redraw(current_menu) == OP_REDRAW) diff --git a/mh.c b/mh.c index 53bf776b9..094515895 100644 --- a/mh.c +++ b/mh.c @@ -141,8 +141,7 @@ static short mhs_set(struct MhSequences *mhs, int i, short f) static int mh_read_token(char *t, int *first, int *last) { - char *p = NULL; - p = strchr(t, '-'); + char *p = strchr(t, '-'); if (p) { *p++ = '\0'; @@ -160,7 +159,6 @@ static int mh_read_token(char *t, int *first, int *last) static int mh_read_sequences(struct MhSequences *mhs, const char *path) { - FILE *fp = NULL; int line = 1; char *buf = NULL; char *t = NULL; @@ -172,7 +170,7 @@ static int mh_read_sequences(struct MhSequences *mhs, const char *path) char pathname[_POSIX_PATH_MAX]; snprintf(pathname, sizeof(pathname), "%s/.mh_sequences", path); - fp = fopen(pathname, "r"); + FILE *fp = fopen(pathname, "r"); if (!fp) return 0; /* yes, ask callers to silently ignore the error */ @@ -694,13 +692,13 @@ static void maildir_free_maildir(struct Maildir **md) void maildir_parse_flags(struct Header *h, const char *path) { - char *p = NULL, *q = NULL; + char *q = NULL; h->flagged = false; h->read = false; h->replied = false; - p = strrchr(path, ':'); + char *p = strrchr(path, ':'); if (p && (mutt_str_strncmp(p + 1, "2,", 2) == 0)) { p += 3; @@ -819,9 +817,7 @@ struct Header *maildir_parse_stream(int magic, FILE *f, const char *fname, struct Header *maildir_parse_message(int magic, const char *fname, bool is_old, struct Header *h) { - FILE *f = NULL; - - f = fopen(fname, "r"); + FILE *f = fopen(fname, "r"); if (f) { h = maildir_parse_stream(magic, f, fname, is_old, h); @@ -1026,9 +1022,9 @@ static struct Maildir *maildir_merge_lists(struct Maildir *left, struct Maildir static struct Maildir *maildir_ins_sort(struct Maildir *list, int (*cmp)(struct Maildir *, struct Maildir *)) { - struct Maildir *tmp = NULL, *last = NULL, *ret = NULL, *back = NULL; + struct Maildir *tmp = NULL, *last = NULL, *back = NULL; - ret = list; + struct Maildir *ret = list; list = list->next; ret->next = NULL; @@ -1130,17 +1126,14 @@ static void maildir_delayed_parsing(struct Context *ctx, struct Maildir **md, int count; int sort = 0; #ifdef USE_HCACHE - header_cache_t *hc = NULL; - void *data = NULL; const char *key = NULL; size_t keylen; - struct timeval *when = NULL; struct stat lastchanged; int ret; #endif #ifdef USE_HCACHE - hc = mutt_hcache_open(HeaderCache, ctx->path, NULL); + header_cache_t *hc = mutt_hcache_open(HeaderCache, ctx->path, NULL); #endif for (p = *md, count = 0; p; p = p->next, count++) @@ -1190,8 +1183,8 @@ static void maildir_delayed_parsing(struct Context *ctx, struct Maildir **md, key = p->h->path + 3; keylen = maildir_hcache_keylen(key); } - data = mutt_hcache_fetch(hc, key, keylen); - when = (struct timeval *) data; + void *data = mutt_hcache_fetch(hc, key, keylen); + struct timeval *when = (struct timeval *) data; if (data != NULL && !ret && lastchanged.st_mtime <= when->tv_sec) { @@ -1751,20 +1744,17 @@ static int mh_commit_message(struct Context *ctx, struct Message *msg) static int mh_rewrite_message(struct Context *ctx, int msgno) { struct Header *h = ctx->hdrs[msgno]; - struct Message *dest = NULL; - - int rc; bool restore = true; long old_body_offset = h->content->offset; long old_body_length = h->content->length; long old_hdr_lines = h->lines; - dest = mx_open_new_message(ctx, h, 0); + struct Message *dest = mx_open_new_message(ctx, h, 0); if (!dest) return -1; - rc = mutt_copy_message_ctx(dest->fp, ctx, h, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN); + int rc = mutt_copy_message_ctx(dest->fp, ctx, h, MUTT_CM_UPDATE, CH_UPDATE | CH_UPDATE_LEN); if (rc == 0) { char oldpath[_POSIX_PATH_MAX]; @@ -1857,9 +1847,8 @@ static int maildir_sync_message(struct Context *ctx, int msgno) char fullpath[_POSIX_PATH_MAX]; char oldpath[_POSIX_PATH_MAX]; char suffix[16]; - char *p = NULL; - p = strrchr(h->path, '/'); + char *p = strrchr(h->path, '/'); if (!p) { mutt_debug(1, "%s: unable to find subdir!\n", h->path); @@ -1985,14 +1974,12 @@ int mh_sync_mailbox_message(struct Context *ctx, int msgno) static char *maildir_canon_filename(char *dest, const char *src, size_t l) { - char *t = NULL, *u = NULL; - - t = strrchr(src, '/'); + char *t = strrchr(src, '/'); if (t) src = t + 1; mutt_str_strfcpy(dest, src, l); - u = strrchr(dest, ':'); + char *u = strrchr(dest, ':'); if (u) *u = '\0'; @@ -2432,7 +2419,6 @@ static FILE *md_open_find_message(const char *folder, const char *unique, char tunique[_POSIX_PATH_MAX]; char fname[LONG_STRING]; - DIR *dp = NULL; struct dirent *de = NULL; FILE *fp = NULL; @@ -2440,7 +2426,7 @@ static FILE *md_open_find_message(const char *folder, const char *unique, snprintf(dir, sizeof(dir), "%s/%s", folder, subfolder); - dp = opendir(dir); + DIR *dp = opendir(dir); if (!dp) { errno = ENOENT; @@ -2472,13 +2458,12 @@ static FILE *md_open_find_message(const char *folder, const char *unique, FILE *maildir_open_find_message(const char *folder, const char *msg, char **newname) { char unique[_POSIX_PATH_MAX]; - FILE *fp = NULL; static unsigned int new_hits = 0, cur_hits = 0; /* simple dynamic optimization */ maildir_canon_filename(unique, msg, sizeof(unique)); - fp = md_open_find_message(folder, unique, new_hits > cur_hits ? "new" : "cur", newname); + FILE *fp = md_open_find_message(folder, unique, new_hits > cur_hits ? "new" : "cur", newname); if (fp || (errno != ENOENT)) { if (new_hits < UINT_MAX && cur_hits < UINT_MAX) @@ -2554,11 +2539,10 @@ int maildir_check_empty(const char *path) */ int mh_check_empty(const char *path) { - DIR *dp = NULL; struct dirent *de = NULL; int r = 1; /* assume empty until we find a message */ - dp = opendir(path); + DIR *dp = opendir(path); if (!dp) return -1; while ((de = readdir(dp))) diff --git a/mutt/address.c b/mutt/address.c index dbcbdabd6..4879a154c 100644 --- a/mutt/address.c +++ b/mutt/address.c @@ -57,7 +57,7 @@ static void free_address(struct Address **a) return; FREE(&(*a)->personal); FREE(&(*a)->mailbox); - FREE(&(*a)); + FREE(a); } /** @@ -412,11 +412,10 @@ struct Address *mutt_addr_new(void) */ int mutt_addr_remove_from_list(struct Address **a, const char *mailbox) { - struct Address *p = NULL, *last = NULL, *t = NULL; int rc = -1; - p = *a; - last = NULL; + struct Address *p = *a; + struct Address *last = NULL; while (p) { if (mutt_str_strcasecmp(mailbox, p->mailbox) == 0) @@ -425,7 +424,7 @@ int mutt_addr_remove_from_list(struct Address **a, const char *mailbox) last->next = p->next; else (*a) = p->next; - t = p; + struct Address *t = p; p = p->next; free_address(&t); rc = 0; @@ -469,11 +468,11 @@ struct Address *mutt_addr_parse_list(struct Address *top, const char *s) const char *ps = NULL; char comment[LONG_STRING], phrase[LONG_STRING]; size_t phraselen = 0, commentlen = 0; - struct Address *cur = NULL, *last = NULL; + struct Address *cur = NULL; AddressError = 0; - last = top; + struct Address *last = top; while (last && last->next) last = last->next; @@ -630,17 +629,14 @@ struct Address *mutt_addr_parse_list(struct Address *top, const char *s) */ struct Address *mutt_addr_parse_list2(struct Address *p, const char *s) { - const char *q = NULL; - /* check for a simple whitespace separated list of addresses */ - q = strpbrk(s, "\"<>():;,\\"); + const char *q = strpbrk(s, "\"<>():;,\\"); if (!q) { char tmp[HUGE_STRING]; - char *r = NULL; mutt_str_strfcpy(tmp, s, sizeof(tmp)); - r = tmp; + char *r = tmp; while ((r = strtok(r, " \t")) != NULL) { p = mutt_addr_parse_list(p, r); @@ -1127,7 +1123,6 @@ void mutt_addr_write_single(char *buf, size_t buflen, struct Address *addr, bool if (buflen == 0) goto done; *pbuf++ = ';'; - buflen--; } done: /* no need to check for length here since we already save space at the diff --git a/mutt/buffer.c b/mutt/buffer.c index eb2d96d53..6ef5562a6 100644 --- a/mutt/buffer.c +++ b/mutt/buffer.c @@ -43,9 +43,7 @@ */ struct Buffer *mutt_buffer_new(void) { - struct Buffer *b = NULL; - - b = mutt_mem_malloc(sizeof(struct Buffer)); + struct Buffer *b = mutt_mem_malloc(sizeof(struct Buffer)); mutt_buffer_init(b); diff --git a/mutt/charset.c b/mutt/charset.c index 657827cf7..26635ae86 100644 --- a/mutt/charset.c +++ b/mutt/charset.c @@ -309,11 +309,10 @@ int mutt_ch_convert_nonmime_string(char **ps) */ void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name) { - char *p = NULL, *ext = NULL; char in[LONG_STRING], scratch[LONG_STRING]; mutt_str_strfcpy(in, name, sizeof(in)); - ext = strchr(in, '/'); + char *ext = strchr(in, '/'); if (ext) *ext++ = '\0'; @@ -349,7 +348,7 @@ void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name) mutt_str_strfcpy(buf, scratch, buflen); /* for cosmetics' sake, transform to lowercase. */ - for (p = buf; *p; p++) + for (char *p = buf; *p; p++) *p = tolower(*p); out: @@ -767,13 +766,14 @@ struct FgetConv *mutt_ch_fgetconv_open(FILE *file, const char *from, const char { struct FgetConv *fc = NULL; iconv_t cd = (iconv_t) -1; - static const char *repls[] = { "\357\277\275", "?", 0 }; if (from && to) cd = mutt_ch_iconv_open(to, from, flags); if (cd != (iconv_t) -1) { + static const char *repls[] = { "\357\277\275", "?", 0 }; + fc = mutt_mem_malloc(sizeof(struct FgetConv)); fc->p = fc->ob = fc->bufo; fc->ib = fc->bufi; diff --git a/mutt/date.c b/mutt/date.c index d57264eca..9f492c430 100644 --- a/mutt/date.c +++ b/mutt/date.c @@ -444,7 +444,6 @@ bool mutt_date_is_day_name(const char *s) time_t mutt_date_parse_date(const char *s, struct Tz *tz_out) { int count = 0; - char *t = NULL; int hour, min, sec; struct tm tm; int i; @@ -463,7 +462,7 @@ time_t mutt_date_parse_date(const char *s, struct Tz *tz_out) mutt_str_strfcpy(scratch, s, sizeof(scratch)); /* kill the day of the week, if it exists. */ - t = strchr(scratch, ','); + char *t = strchr(scratch, ','); if (t) t++; else @@ -539,11 +538,10 @@ time_t mutt_date_parse_date(const char *s, struct Tz *tz_out) } else { - struct Tz *tz = NULL; - /* This is safe to do: A pointer to a struct equals a pointer to its first element */ - tz = bsearch(ptz, TimeZones, mutt_array_size(TimeZones), sizeof(struct Tz), - (int (*)(const void *, const void *)) mutt_str_strcasecmp); + struct Tz *tz = + bsearch(ptz, TimeZones, mutt_array_size(TimeZones), sizeof(struct Tz), + (int (*)(const void *, const void *)) mutt_str_strcasecmp); if (tz) { diff --git a/mutt/file.c b/mutt/file.c index f543f23a4..025931522 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -420,13 +420,12 @@ int mutt_file_safe_rename(const char *src, const char *target) */ int mutt_file_rmtree(const char *path) { - DIR *dirp = NULL; struct dirent *de = NULL; char cur[LONG_STRING]; struct stat statbuf; int rc = 0; - dirp = opendir(path); + DIR *dirp = opendir(path); if (!dirp) { mutt_debug(1, "error opening directory %s\n", path); @@ -1301,10 +1300,7 @@ int mutt_file_to_absolute_path(char *path, const char *reference) */ char *mutt_file_read_keyword(const char *file, char *buffer, size_t buflen) { - FILE *fp = NULL; - char *start = NULL; - - fp = mutt_file_fopen(file, "r"); + FILE *fp = mutt_file_fopen(file, "r"); if (!fp) return NULL; @@ -1315,7 +1311,7 @@ char *mutt_file_read_keyword(const char *file, char *buffer, size_t buflen) return NULL; SKIPWS(buffer); - start = buffer; + char *start = buffer; while (*buffer && !isspace(*buffer)) buffer++; diff --git a/mutt/hash.c b/mutt/hash.c index d0588b056..cdfcde0e8 100644 --- a/mutt/hash.c +++ b/mutt/hash.c @@ -155,11 +155,8 @@ static struct Hash *new_hash(int nelem) static struct HashElem *union_hash_insert(struct Hash *table, union HashKey key, int type, void *data) { - struct HashElem *ptr = NULL; - unsigned int h; - - ptr = mutt_mem_malloc(sizeof(struct HashElem)); - h = table->gen_hash(key, table->nelem); + struct HashElem *ptr = mutt_mem_malloc(sizeof(struct HashElem)); + unsigned int h = table->gen_hash(key, table->nelem); ptr->key = key; ptr->data = data; ptr->type = type; diff --git a/mutt/idna.c b/mutt/idna.c index 5f200e73b..b8fdb1646 100644 --- a/mutt/idna.c +++ b/mutt/idna.c @@ -123,18 +123,15 @@ static bool check_idn(char *domain) */ char *mutt_idna_intl_to_local(const char *user, const char *domain, int flags) { - char *local_user = NULL, *local_domain = NULL, *mailbox = NULL; + char *mailbox = NULL; char *reversed_user = NULL, *reversed_domain = NULL; char *tmp = NULL; -#ifdef HAVE_LIBIDN - bool is_idn_encoded = false; -#endif /* HAVE_LIBIDN */ - local_user = mutt_str_strdup(user); - local_domain = mutt_str_strdup(domain); + char *local_user = mutt_str_strdup(user); + char *local_domain = mutt_str_strdup(domain); #ifdef HAVE_LIBIDN - is_idn_encoded = check_idn(local_domain); + bool is_idn_encoded = check_idn(local_domain); if (is_idn_encoded && IdnDecode) { if (idna_to_unicode_8z8z(local_domain, &tmp, IDNA_ALLOW_UNASSIGNED) != IDNA_SUCCESS) @@ -232,12 +229,11 @@ cleanup: */ char *mutt_idna_local_to_intl(const char *user, const char *domain) { - char *intl_user = NULL, *intl_domain = NULL; char *mailbox = NULL; char *tmp = NULL; - intl_user = mutt_str_strdup(user); - intl_domain = mutt_str_strdup(domain); + char *intl_user = mutt_str_strdup(user); + char *intl_domain = mutt_str_strdup(domain); /* we don't want charset-hook effects, so we set flags to 0 */ if (mutt_ch_convert_string(&intl_user, Charset, "utf-8", 0) == -1) diff --git a/mutt/mbyte.c b/mutt/mbyte.c index a9cc43021..722f6fced 100644 --- a/mutt/mbyte.c +++ b/mutt/mbyte.c @@ -287,11 +287,8 @@ size_t mutt_mb_mbstowcs(wchar_t **pwbuf, size_t *pwbuflen, size_t i, char *buf) wchar_t wc; mbstate_t st; size_t k; - wchar_t *wbuf = NULL; - size_t wbuflen; - - wbuf = *pwbuf; - wbuflen = *pwbuflen; + wchar_t *wbuf = *pwbuf; + size_t wbuflen = *pwbuflen; while (*buf) { @@ -410,14 +407,13 @@ bool mutt_mb_is_display_corrupting_utf8(wchar_t wc) */ int mutt_mb_filter_unprintable(char **s) { - struct Buffer *b = NULL; wchar_t wc; size_t k, k2; char scratch[MB_LEN_MAX + 1]; char *p = *s; mbstate_t mbstate1, mbstate2; - b = mutt_buffer_new(); + struct Buffer *b = mutt_buffer_new(); if (!b) return -1; memset(&mbstate1, 0, sizeof(mbstate1)); diff --git a/mutt/regex.c b/mutt/regex.c index 151e1d6d3..87230e8d7 100644 --- a/mutt/regex.c +++ b/mutt/regex.c @@ -592,11 +592,8 @@ struct ReplaceList *mutt_replacelist_new(void) */ int mutt_replacelist_remove(struct ReplaceList **rl, const char *pat) { - struct ReplaceList *cur = NULL, *prev = NULL; - int nremoved = 0; - /* Being first is a special case. */ - cur = *rl; + struct ReplaceList *cur = *rl; if (!cur) return 0; if (cur->regex && (mutt_str_strcmp(cur->regex->pattern, pat) == 0)) @@ -608,7 +605,8 @@ int mutt_replacelist_remove(struct ReplaceList **rl, const char *pat) return 1; } - prev = cur; + int nremoved = 0; + struct ReplaceList *prev = cur; for (cur = prev->next; cur;) { if (mutt_str_strcmp(cur->regex->pattern, pat) == 0) diff --git a/mutt/rfc2047.c b/mutt/rfc2047.c index 537876967..47b44b5ef 100644 --- a/mutt/rfc2047.c +++ b/mutt/rfc2047.c @@ -429,7 +429,7 @@ static int rfc2047_encode(const char *d, size_t dlen, int col, const char *fromc int rc = 0; char *buf = NULL; size_t bufpos, buflen; - char *u = NULL, *t0 = NULL, *t1 = NULL, *t = NULL; + char *t0 = NULL, *t1 = NULL, *t = NULL; char *s0 = NULL, *s1 = NULL; size_t ulen, r, wlen = 0; encoder_t encoder = NULL; @@ -438,7 +438,7 @@ static int rfc2047_encode(const char *d, size_t dlen, int col, const char *fromc char *icode = "utf-8"; /* Try to convert to UTF-8. */ - u = mutt_str_substr_dup(d, d + dlen); + char *u = mutt_str_substr_dup(d, d + dlen); if (mutt_ch_convert_string(&u, fromcode, icode, 0)) { rc = 1; diff --git a/mutt/string.c b/mutt/string.c index e2bccd2e0..122a84f9b 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -732,7 +732,7 @@ size_t mutt_str_lws_rlen(const char *s, size_t n) const char *p = s + n - 1; size_t len = n; - if (n <= 0) + if (n == 0) return 0; if (strchr("\r\n", *p)) /* LWS doesn't end with CRLF */ diff --git a/mutt_lua.c b/mutt_lua.c index 60f1e4873..15dd46a47 100644 --- a/mutt_lua.c +++ b/mutt_lua.c @@ -152,8 +152,7 @@ static int lua_mutt_set(lua_State *l) { long num = lua_tointeger(l, -1); opt.var = (void *) num; - if ((num != MUTT_YES) && (num != MUTT_NO) && - (num != MUTT_ASKYES) && (num != MUTT_ASKNO)) + if ((num != MUTT_YES) && (num != MUTT_NO) && (num != MUTT_ASKYES) && (num != MUTT_ASKNO)) { luaL_error(l, "Invalid opt for quad option %s (one of " diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 45c417082..2643fdc45 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -757,11 +757,10 @@ static int update_header_tags(struct Header *h, notmuch_message_t *msg) static int update_message_path(struct Header *h, const char *path) { struct NmHdrData *data = h->data; - char *p = NULL; mutt_debug(2, "nm: path update requested path=%s, (%s)\n", path, data->virtual_id); - p = strrchr(path, '/'); + char *p = strrchr(path, '/'); if (p && ((p - path) > 3) && ((strncmp(p - 3, "cur", 3) == 0) || (strncmp(p - 3, "new", 3) == 0) || (strncmp(p - 3, "tmp", 3) == 0))) @@ -1311,10 +1310,9 @@ static int rename_maildir_filename(const char *old, char *newpath, size_t newsz, char filename[_POSIX_PATH_MAX]; char suffix[_POSIX_PATH_MAX]; char folder[_POSIX_PATH_MAX]; - char *p = NULL; mutt_str_strfcpy(folder, old, sizeof(folder)); - p = strrchr(folder, '/'); + char *p = strrchr(folder, '/'); if (p) { *p = '\0'; @@ -1800,15 +1798,12 @@ done: bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr) { - char *orig_str = NULL; char *new_str = NULL; struct NmCtxData *data = get_ctxdata(ctx); - notmuch_database_t *db = NULL; - notmuch_query_t *q = NULL; bool result = false; - db = get_db(data, false); - orig_str = get_query_string(data, true); + notmuch_database_t *db = get_db(data, false); + char *orig_str = get_query_string(data, true); if (!db || !orig_str) return false; @@ -1818,7 +1813,7 @@ bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr) mutt_debug(2, "nm: checking if message is still queried: %s\n", new_str); - q = notmuch_query_create(db, new_str); + notmuch_query_t *q = notmuch_query_create(db, new_str); switch (data->query_type) { diff --git a/mutt_socket.c b/mutt_socket.c index f9f1c889d..daabc9eff 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -66,7 +66,6 @@ void mutt_socket_free(struct Connection *conn) */ struct Connection *mutt_conn_find(const struct Connection *start, const struct Account *account) { - struct Connection *conn = NULL; struct Url url; char hook[LONG_STRING]; @@ -76,7 +75,7 @@ struct Connection *mutt_conn_find(const struct Connection *start, const struct A url_tostring(&url, hook, sizeof(hook), 0); mutt_account_hook(hook); - conn = start ? TAILQ_NEXT(start, entries) : TAILQ_FIRST(&Connections); + struct Connection *conn = start ? TAILQ_NEXT(start, entries) : TAILQ_FIRST(&Connections); while (conn) { if (mutt_account_match(account, &(conn->account))) diff --git a/muttlib.c b/muttlib.c index 19ffd780f..28d0aea4a 100644 --- a/muttlib.c +++ b/muttlib.c @@ -208,13 +208,10 @@ char *mutt_expand_path_regex(char *s, size_t slen, int regex) case '@': { - struct Header *h = NULL; - struct Address *alias = NULL; - - alias = mutt_alias_lookup(s + 1); + struct Address *alias = mutt_alias_lookup(s + 1); if (alias) { - h = mutt_header_new(); + struct Header *h = mutt_header_new(); h->env = mutt_env_new(); h->env->from = h->env->to = alias; mutt_default_save(p, sizeof(p), h); @@ -707,9 +704,7 @@ void mutt_save_path(char *d, size_t dsize, struct Address *a) mutt_str_strfcpy(d, a->mailbox, dsize); if (!SaveAddress) { - char *p = NULL; - - p = strpbrk(d, "%@"); + char *p = strpbrk(d, "%@"); if (p) *p = 0; } @@ -744,7 +739,6 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c char prefix[SHORT_STRING], tmp[LONG_STRING], *cp = NULL, *wptr = buf, ch; char if_str[SHORT_STRING], else_str[SHORT_STRING]; size_t wlen, count, len, wid; - pid_t pid; FILE *filter = NULL; char *recycler = NULL; @@ -775,7 +769,6 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c /* n-off is the number of backslashes. */ if (off > 0 && ((n - off) % 2) == 0) { - struct Buffer *srcbuf = NULL, *word = NULL, *command = NULL; char srccopy[LONG_STRING]; int i = 0; @@ -785,10 +778,10 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c srccopy[n - 1] = '\0'; /* prepare BUFFERs */ - srcbuf = mutt_buffer_from(srccopy); + struct Buffer *srcbuf = mutt_buffer_from(srccopy); srcbuf->dptr = srcbuf->data; - word = mutt_buffer_new(); - command = mutt_buffer_new(); + struct Buffer *word = mutt_buffer_new(); + struct Buffer *command = mutt_buffer_new(); /* Iterate expansions across successive arguments */ do @@ -821,7 +814,7 @@ void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const c col -= wlen; /* reset to passed in value */ wptr = buf; /* reset write ptr */ - pid = mutt_create_filter(command->data, NULL, &filter, NULL); + pid_t pid = mutt_create_filter(command->data, NULL, &filter, NULL); if (pid != -1) { int rc; diff --git a/mx.c b/mx.c index d29b063a1..9773cb4b8 100644 --- a/mx.c +++ b/mx.c @@ -642,7 +642,6 @@ static int trash_append(struct Context *ctx) int mx_close_mailbox(struct Context *ctx, int *index_hint) { int i, move_messages = 0, purge = 1, read_msgs = 0; - int check; struct Context f; char mbox[_POSIX_PATH_MAX]; char buf[SHORT_STRING]; @@ -835,7 +834,7 @@ int mx_close_mailbox(struct Context *ctx, int *index_hint) /* allow IMAP to preserve the deleted flag across sessions */ if (ctx->magic == MUTT_IMAP) { - check = imap_sync_mailbox(ctx, purge); + int check = imap_sync_mailbox(ctx, purge); if (check != 0) { ctx->closing = false; @@ -857,7 +856,7 @@ int mx_close_mailbox(struct Context *ctx, int *index_hint) if (ctx->changed || ctx->deleted) { - check = sync_mailbox(ctx, index_hint); + int check = sync_mailbox(ctx, index_hint); if (check != 0) { ctx->closing = false; diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index dfd6341ac..9c45318da 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -1099,7 +1099,7 @@ const char *crypt_get_fingerprint_or_id(char *p, const char **pphint, const char **ppl, const char **pps) { const char *ps = NULL, *pl = NULL, *phint = NULL; - char *pfcopy = NULL, *pf = NULL, *s1 = NULL, *s2 = NULL; + char *pfcopy = NULL, *s1 = NULL, *s2 = NULL; char c; int isid; size_t hexdigits; @@ -1111,7 +1111,7 @@ const char *crypt_get_fingerprint_or_id(char *p, const char **pphint, * if an ID was found and to simplify logic in the key loop's inner * condition of the caller. */ - pf = mutt_str_skip_whitespace(p); + char *pf = mutt_str_skip_whitespace(p); if (mutt_str_strncasecmp(pf, "0x", 2) == 0) pf += 2; diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 06cc5a938..bb4b9cc28 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -165,9 +165,7 @@ static int digit_or_letter(const unsigned char *s) */ static void print_utf8(FILE *fp, const char *buf, size_t len) { - char *tstr = NULL; - - tstr = mutt_mem_malloc(len + 1); + char *tstr = mutt_mem_malloc(len + 1); memcpy(tstr, buf, len); tstr[len] = 0; @@ -512,12 +510,11 @@ static gpgme_data_t create_gpgme_data(void) static gpgme_data_t body_to_data_object(struct Body *a, int convert) { char tempfile[_POSIX_PATH_MAX]; - FILE *fptmp = NULL; int err = 0; gpgme_data_t data; mutt_mktemp(tempfile, sizeof(tempfile)); - fptmp = mutt_file_fopen(tempfile, "w+"); + FILE *fptmp = mutt_file_fopen(tempfile, "w+"); if (!fptmp) { mutt_perror(tempfile); @@ -1114,31 +1111,26 @@ struct Body *smime_gpgme_sign_message(struct Body *a) */ struct Body *pgp_gpgme_encrypt_message(struct Body *a, char *keylist, int sign) { - char *outfile = NULL; - struct Body *t = NULL; - gpgme_key_t *rset = NULL; - gpgme_data_t plaintext; - - rset = create_recipient_set(keylist, GPGME_PROTOCOL_OpenPGP); + gpgme_key_t *rset = create_recipient_set(keylist, GPGME_PROTOCOL_OpenPGP); if (!rset) return NULL; if (sign) convert_to_7bit(a); - plaintext = body_to_data_object(a, 0); + gpgme_data_t plaintext = body_to_data_object(a, 0); if (!plaintext) { free_recipient_set(&rset); return NULL; } - outfile = encrypt_gpgme_object(plaintext, rset, 0, sign); + char *outfile = encrypt_gpgme_object(plaintext, rset, 0, sign); gpgme_data_release(plaintext); free_recipient_set(&rset); if (!outfile) return NULL; - t = mutt_body_new(); + struct Body *t = mutt_body_new(); t->type = TYPEMULTIPART; t->subtype = mutt_str_strdup("encrypted"); t->encoding = ENC7BIT; @@ -1179,12 +1171,7 @@ struct Body *pgp_gpgme_encrypt_message(struct Body *a, char *keylist, int sign) */ struct Body *smime_gpgme_build_smime_entity(struct Body *a, char *keylist) { - char *outfile = NULL; - struct Body *t = NULL; - gpgme_key_t *rset = NULL; - gpgme_data_t plaintext; - - rset = create_recipient_set(keylist, GPGME_PROTOCOL_CMS); + gpgme_key_t *rset = create_recipient_set(keylist, GPGME_PROTOCOL_CMS); if (!rset) return NULL; @@ -1192,20 +1179,20 @@ struct Body *smime_gpgme_build_smime_entity(struct Body *a, char *keylist) * clients depend on this for signed+encrypted messages: they do not * convert line endings between decrypting and checking the * signature. See #3904. */ - plaintext = body_to_data_object(a, 1); + gpgme_data_t plaintext = body_to_data_object(a, 1); if (!plaintext) { free_recipient_set(&rset); return NULL; } - outfile = encrypt_gpgme_object(plaintext, rset, 1, 0); + char *outfile = encrypt_gpgme_object(plaintext, rset, 1, 0); gpgme_data_release(plaintext); free_recipient_set(&rset); if (!outfile) return NULL; - t = mutt_body_new(); + struct Body *t = mutt_body_new(); t->type = TYPEAPPLICATION; t->subtype = mutt_str_strdup("pkcs7-mime"); mutt_param_set(&t->parameter, "name", "smime.p7m"); @@ -1410,11 +1397,10 @@ static void show_fingerprint(gpgme_key_t key, struct State *state) */ static void show_one_sig_validity(gpgme_ctx_t ctx, int idx, struct State *s) { - gpgme_verify_result_t result = NULL; gpgme_signature_t sig = NULL; const char *txt = NULL; - result = gpgme_op_verify_result(ctx); + gpgme_verify_result_t result = gpgme_op_verify_result(ctx); if (result) for (sig = result->signatures; sig && (idx > 0); sig = sig->next, idx--) ; @@ -2374,17 +2360,15 @@ int pgp_gpgme_check_traditional(FILE *fp, struct Body *b, int just_one) void pgp_gpgme_invoke_import(const char *fname) { gpgme_data_t keydata; - gpgme_error_t err; - FILE *in = NULL; FILE *out = NULL; - in = mutt_file_fopen(fname, "r"); + FILE *in = mutt_file_fopen(fname, "r"); if (!in) return; /* Note that the stream, "in", needs to be kept open while the keydata * is used. */ - err = gpgme_data_new_from_stream(&keydata, in); + gpgme_error_t err = gpgme_data_new_from_stream(&keydata, in); if (err != GPG_ERR_NO_ERROR) { mutt_file_fclose(&in); @@ -2421,11 +2405,9 @@ static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset) { char buf[HUGE_STRING]; bool complete, armor_header; - struct FgetConv *fc = NULL; - char *fname = NULL; FILE *fp = NULL; - fname = data_object_to_tempfile(data, NULL, &fp); + char *fname = data_object_to_tempfile(data, NULL, &fp); if (!fname) { mutt_file_fclose(&fp); @@ -2438,7 +2420,7 @@ static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset) * be a wrong label, so we want the ability to do corrections via * charset-hooks. Therefore we set flags to MUTT_ICONV_HOOK_FROM. */ - fc = mutt_ch_fgetconv_open(fp, charset, Charset, MUTT_ICONV_HOOK_FROM); + struct FgetConv *fc = mutt_ch_fgetconv_open(fp, charset, Charset, MUTT_ICONV_HOOK_FROM); for (complete = true, armor_header = true; mutt_ch_fgetconvs(buf, sizeof(buf), fc) != NULL; complete = (strchr(buf, '\n') != NULL)) @@ -2482,7 +2464,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) bool pgp_keyblock = false; bool clearsign = false; long bytes; - LOFF_T last_pos, offset; + LOFF_T last_pos; char buf[HUGE_STRING]; FILE *pgpout = NULL; @@ -2510,7 +2492,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) if (fgets(buf, sizeof(buf), s->fpin) == NULL) break; - offset = ftello(s->fpin); + LOFF_T offset = ftello(s->fpin); bytes -= (offset - last_pos); /* don't rely on mutt_str_strlen(buf) */ last_pos = offset; @@ -2658,10 +2640,9 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) } else if (pgpout) { - struct FgetConv *fc = NULL; int c; rewind(pgpout); - fc = mutt_ch_fgetconv_open(pgpout, "utf-8", Charset, 0); + struct FgetConv *fc = mutt_ch_fgetconv_open(pgpout, "utf-8", Charset, 0); while ((c = mutt_ch_fgetconv(fc)) != EOF) { state_putc(c, s); @@ -2725,15 +2706,13 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) { char tempfile[_POSIX_PATH_MAX]; - FILE *fpout = NULL; - struct Body *tattach = NULL; int is_signed; int rc = 0; mutt_debug(2, "Entering handler\n"); mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = mutt_file_fopen(tempfile, "w+"); + FILE *fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { if (s->flags & MUTT_DISPLAY) @@ -2743,7 +2722,7 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) return -1; } - tattach = decrypt_part(a, s, fpout, 0, &is_signed); + struct Body *tattach = decrypt_part(a, s, fpout, 0, &is_signed); if (tattach) { tattach->goodsig = is_signed > 0; @@ -2801,8 +2780,6 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) int smime_gpgme_application_handler(struct Body *a, struct State *s) { char tempfile[_POSIX_PATH_MAX]; - FILE *fpout = NULL; - struct Body *tattach = NULL; int is_signed; int rc = 0; @@ -2810,7 +2787,7 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) a->warnsig = false; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = mutt_file_fopen(tempfile, "w+"); + FILE *fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { if (s->flags & MUTT_DISPLAY) @@ -2820,7 +2797,7 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) return -1; } - tattach = decrypt_part(a, s, fpout, 1, &is_signed); + struct Body *tattach = decrypt_part(a, s, fpout, 1, &is_signed); if (tattach) { tattach->goodsig = is_signed > 0; @@ -2916,14 +2893,12 @@ static const char *crypt_format_str(char *buf, size_t buflen, size_t col, int co unsigned long data, enum FormatFlag flags) { char fmt[SHORT_STRING]; - struct CryptEntry *entry = NULL; - struct CryptKeyInfo *key = NULL; int kflags = 0; int optional = (flags & MUTT_FORMAT_OPTIONAL); const char *s = NULL; - entry = (struct CryptEntry *) data; - key = entry->key; + struct CryptEntry *entry = (struct CryptEntry *) data; + struct CryptKeyInfo *key = entry->key; /* if (isupper ((unsigned char) op)) */ /* key = pkey; */ @@ -3043,15 +3018,14 @@ static const char *crypt_format_str(char *buf, size_t buflen, size_t col, int co case '[': { - const char *cp = NULL; - char buf2[SHORT_STRING], *p = NULL; + char buf2[SHORT_STRING]; int do_locales; struct tm *tm = NULL; size_t len; - p = buf; + char *p = buf; - cp = src; + const char *cp = src; if (*cp == '!') { do_locales = 0; @@ -3432,10 +3406,8 @@ static struct DnArray *parse_dn(const char *string) if (arrayidx >= arraysize) { /* neomutt lacks a real mutt_mem_realloc - so we need to copy */ - struct DnArray *a2 = NULL; - arraysize += 5; - a2 = mutt_mem_malloc((arraysize + 1) * sizeof(*array)); + struct DnArray *a2 = mutt_mem_malloc((arraysize + 1) * sizeof(*array)); for (int i = 0; i < arrayidx; i++) { a2[i].key = array[i].key; @@ -3855,7 +3827,6 @@ static void print_key_info(gpgme_key_t key, FILE *fp) */ static void verify_key(struct CryptKeyInfo *key) { - FILE *fp = NULL; char cmd[LONG_STRING], tempfile[_POSIX_PATH_MAX]; const char *s = NULL; gpgme_ctx_t listctx = NULL; @@ -3864,7 +3835,7 @@ static void verify_key(struct CryptKeyInfo *key) int maxdepth = 100; mutt_mktemp(tempfile, sizeof(tempfile)); - fp = mutt_file_fopen(tempfile, "w"); + FILE *fp = mutt_file_fopen(tempfile, "w"); if (!fp) { mutt_perror(_("Can't create temporary file")); @@ -3987,14 +3958,13 @@ static char *list_to_pattern(struct ListHead *list) static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int app, int secret) { struct CryptKeyInfo *db = NULL, *k = NULL, **kend = NULL; - char *pattern = NULL; gpgme_error_t err; gpgme_ctx_t ctx; gpgme_key_t key; int idx; gpgme_user_id_t uid = NULL; - pattern = list_to_pattern(hints); + char *pattern = list_to_pattern(hints); if (!pattern) return NULL; @@ -4136,14 +4106,11 @@ static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int */ static void crypt_add_string_to_hints(struct ListHead *hints, const char *str) { - char *scratch = NULL; - char *t = NULL; - - scratch = mutt_str_strdup(str); + char *scratch = mutt_str_strdup(str); if (!scratch) return; - for (t = strtok(scratch, " ,.:\"()<>\n"); t; t = strtok(NULL, " ,.:\"()<>\n")) + for (char *t = strtok(scratch, " ,.:\"()<>\n"); t; t = strtok(NULL, " ,.:\"()<>\n")) { if (strlen(t) > 3) mutt_list_insert_tail(hints, mutt_str_strdup(t)); @@ -4163,8 +4130,6 @@ static struct CryptKeyInfo *crypt_select_key(struct CryptKeyInfo *keys, unsigned int app, int *forced_valid) { int keymax; - struct CryptKeyInfo **key_table = NULL; - struct Menu *menu = NULL; int i; bool done = false; char helpstr[LONG_STRING], buf[LONG_STRING]; @@ -4177,7 +4142,7 @@ static struct CryptKeyInfo *crypt_select_key(struct CryptKeyInfo *keys, /* build the key table */ keymax = i = 0; - key_table = NULL; + struct CryptKeyInfo **key_table = NULL; for (k = keys; k; k = k->next) { if (!PgpShowUnusable && (k->flags & KEYFLAG_CANTUSE)) @@ -4234,7 +4199,7 @@ static struct CryptKeyInfo *crypt_select_key(struct CryptKeyInfo *keys, mutt_make_help(buf, sizeof(buf), _("Help"), menu_to_use, OP_HELP); strcat(helpstr, buf); - menu = mutt_menu_new(menu_to_use); + struct Menu *menu = mutt_menu_new(menu_to_use); menu->max = i; menu->make_entry = crypt_entry; menu->help = helpstr; @@ -4483,19 +4448,18 @@ static struct CryptKeyInfo *crypt_getkeybystr(char *p, short abilities, unsigned int app, int *forced_valid) { struct ListHead hints = STAILQ_HEAD_INITIALIZER(hints); - struct CryptKeyInfo *keys = NULL; struct CryptKeyInfo *matches = NULL; struct CryptKeyInfo **matches_endp = &matches; struct CryptKeyInfo *k = NULL; - const char *ps = NULL, *pl = NULL, *pfcopy = NULL, *phint = NULL; + const char *ps = NULL, *pl = NULL, *phint = NULL; mutt_message(_("Looking for keys matching \"%s\"..."), p); *forced_valid = 0; - pfcopy = crypt_get_fingerprint_or_id(p, &phint, &pl, &ps); + const char *pfcopy = crypt_get_fingerprint_or_id(p, &phint, &pl, &ps); crypt_add_string_to_hints(&hints, phint); - keys = get_candidates(&hints, app, (abilities & KEYFLAG_CANSIGN)); + struct CryptKeyInfo *keys = get_candidates(&hints, app, (abilities & KEYFLAG_CANSIGN)); mutt_list_free(&hints); if (!keys) @@ -4751,7 +4715,6 @@ char *smime_gpgme_findkeys(struct Address *addrlist, int oppenc_mode) #ifdef HAVE_GPGME_OP_EXPORT_KEYS struct Body *pgp_gpgme_make_key_attachment(char *tempf) { - struct CryptKeyInfo *key = NULL; gpgme_ctx_t context = NULL; gpgme_key_t export_keys[2]; gpgme_data_t keydata = NULL; @@ -4762,7 +4725,7 @@ struct Body *pgp_gpgme_make_key_attachment(char *tempf) OPT_PGP_CHECK_TRUST = false; - key = crypt_ask_for_key(_("Please enter the key ID: "), NULL, 0, APPLICATION_PGP, NULL); + struct CryptKeyInfo *key = crypt_ask_for_key(_("Please enter the key ID: "), NULL, 0, APPLICATION_PGP, NULL); if (!key) goto bail; export_keys[0] = key->kobj; diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index b73a5983f..00c43f9f3 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -88,16 +88,12 @@ static void fix_uid(char *uid) if (chs && (cd = mutt_ch_iconv_open(chs, "utf-8", 0)) != (iconv_t) -1) { int n = s - uid + 1; /* chars available in original buffer */ - char *buf = NULL; - const char *ib = NULL; - char *ob = NULL; - size_t ibl, obl; - - buf = mutt_mem_malloc(n + 1); - ib = uid; - ibl = d - uid + 1; - ob = buf; - obl = n; + + char *buf = mutt_mem_malloc(n + 1); + const char *ib = uid; + size_t ibl = d - uid + 1; + char *ob = buf; + size_t obl = n; iconv(cd, (ICONV_CONST char **) &ib, &ibl, &ob, &obl); if (!ibl) { diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index b757c96f7..2ee6f4c86 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -167,9 +167,7 @@ static char *pgp_fingerprint(struct PgpKeyInfo *k) */ char *pgp_fpr_or_lkeyid(struct PgpKeyInfo *k) { - char *fingerprint = NULL; - - fingerprint = pgp_fingerprint(k); + char *fingerprint = pgp_fingerprint(k); return fingerprint ? fingerprint : pgp_long_keyid(k); } @@ -271,15 +269,13 @@ static void pgp_copy_clearsigned(FILE *fpin, struct State *s, char *charset) char buf[HUGE_STRING]; bool complete, armor_header; - struct FgetConv *fc = NULL; - rewind(fpin); /* fromcode comes from the MIME Content-Type charset label. It might * be a wrong label, so we want the ability to do corrections via * charset-hooks. Therefore we set flags to MUTT_ICONV_HOOK_FROM. */ - fc = mutt_ch_fgetconv_open(fpin, charset, Charset, MUTT_ICONV_HOOK_FROM); + struct FgetConv *fc = mutt_ch_fgetconv_open(fpin, charset, Charset, MUTT_ICONV_HOOK_FROM); for (complete = true, armor_header = true; mutt_ch_fgetconvs(buf, sizeof(buf), fc) != NULL; complete = (strchr(buf, '\n') != NULL)) @@ -698,13 +694,13 @@ int pgp_check_traditional(FILE *fp, struct Body *b, int just_one) int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) { char sigfile[_POSIX_PATH_MAX], pgperrfile[_POSIX_PATH_MAX]; - FILE *fp = NULL, *pgpout = NULL, *pgperr = NULL; + FILE *pgpout = NULL, *pgperr = NULL; pid_t thepid; int badsig = -1; snprintf(sigfile, sizeof(sigfile), "%s.asc", tempfile); - fp = mutt_file_fopen(sigfile, "w"); + FILE *fp = mutt_file_fopen(sigfile, "w"); if (!fp) { mutt_perror(sigfile); @@ -764,11 +760,10 @@ int pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) static void pgp_extract_keys_from_attachment(FILE *fp, struct Body *top) { struct State s; - FILE *tempfp = NULL; char tempfname[_POSIX_PATH_MAX]; mutt_mktemp(tempfname, sizeof(tempfname)); - tempfp = mutt_file_fopen(tempfname, "w"); + FILE *tempfp = mutt_file_fopen(tempfname, "w"); if (!tempfp) { mutt_perror(tempfname); @@ -820,7 +815,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, return NULL; char buf[LONG_STRING]; - FILE *pgpin = NULL, *pgpout = NULL, *pgperr = NULL, *pgptmp = NULL; + FILE *pgpin = NULL, *pgpout = NULL, *pgptmp = NULL; struct stat info; struct Body *tattach = NULL; char pgperrfile[_POSIX_PATH_MAX]; @@ -829,7 +824,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, int rv; mutt_mktemp(pgperrfile, sizeof(pgperrfile)); - pgperr = mutt_file_fopen(pgperrfile, "w+"); + FILE *pgperr = mutt_file_fopen(pgperrfile, "w+"); if (!pgperr) { mutt_perror(pgperrfile); @@ -1030,12 +1025,12 @@ bail: int pgp_encrypted_handler(struct Body *a, struct State *s) { char tempfile[_POSIX_PATH_MAX]; - FILE *fpout = NULL, *fpin = NULL; + FILE *fpin = NULL; struct Body *tattach = NULL; int rc = 0; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = mutt_file_fopen(tempfile, "w+"); + FILE *fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { if (s->flags & MUTT_DISPLAY) @@ -1101,7 +1096,7 @@ struct Body *pgp_sign_message(struct Body *a) struct Body *t = NULL; char buffer[LONG_STRING]; char sigfile[_POSIX_PATH_MAX], signedfile[_POSIX_PATH_MAX]; - FILE *pgpin = NULL, *pgpout = NULL, *pgperr = NULL, *fp = NULL, *sfp = NULL; + FILE *pgpin = NULL, *pgpout = NULL, *pgperr = NULL, *sfp = NULL; bool err = false; bool empty = true; pid_t thepid; @@ -1109,7 +1104,7 @@ struct Body *pgp_sign_message(struct Body *a) convert_to_7bit(a); /* Signed data _must_ be in 7-bit format. */ mutt_mktemp(sigfile, sizeof(sigfile)); - fp = mutt_file_fopen(sigfile, "w"); + FILE *fp = mutt_file_fopen(sigfile, "w"); if (!fp) { return NULL; @@ -1353,14 +1348,14 @@ struct Body *pgp_encrypt_message(struct Body *a, char *keylist, int sign) char buf[LONG_STRING]; char tempfile[_POSIX_PATH_MAX], pgperrfile[_POSIX_PATH_MAX]; char pgpinfile[_POSIX_PATH_MAX]; - FILE *pgpin = NULL, *pgperr = NULL, *fpout = NULL, *fptmp = NULL; + FILE *pgpin = NULL, *pgperr = NULL, *fptmp = NULL; struct Body *t = NULL; int err = 0; int empty = 0; pid_t thepid; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = mutt_file_fopen(tempfile, "w+"); + FILE *fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { mutt_perror(tempfile); diff --git a/ncrypt/pgpkey.c b/ncrypt/pgpkey.c index 2fc30b04d..4d06698ef 100644 --- a/ncrypt/pgpkey.c +++ b/ncrypt/pgpkey.c @@ -143,16 +143,13 @@ static const char *pgp_entry_fmt(char *buf, size_t buflen, size_t col, int cols, unsigned long data, enum FormatFlag flags) { char fmt[SHORT_STRING]; - struct PgpEntry *entry = NULL; - struct PgpUid *uid = NULL; - struct PgpKeyInfo *key = NULL, *pkey = NULL; int kflags = 0; int optional = (flags & MUTT_FORMAT_OPTIONAL); - entry = (struct PgpEntry *) data; - uid = entry->uid; - key = uid->parent; - pkey = pgp_principal_key(key); + struct PgpEntry *entry = (struct PgpEntry *) data; + struct PgpUid *uid = entry->uid; + struct PgpKeyInfo *key = uid->parent; + struct PgpKeyInfo *pkey = pgp_principal_key(key); if (isupper((unsigned char) op)) key = pkey; @@ -229,15 +226,14 @@ static const char *pgp_entry_fmt(char *buf, size_t buflen, size_t col, int cols, case '[': { - const char *cp = NULL; - char buf2[SHORT_STRING], *p = NULL; + char buf2[SHORT_STRING]; int do_locales; struct tm *tm = NULL; size_t len; - p = buf; + char *p = buf; - cp = src; + const char *cp = src; if (*cp == '!') { do_locales = 0; @@ -740,10 +736,9 @@ struct Body *pgp_make_key_attachment(char *tempf) FILE *devnull = NULL; struct stat sb; pid_t thepid; - struct PgpKeyInfo *key = NULL; OPT_PGP_CHECK_TRUST = false; - key = pgp_ask_for_key(_("Please enter the key ID: "), NULL, 0, PGP_PUBRING); + struct PgpKeyInfo *key = pgp_ask_for_key(_("Please enter the key ID: "), NULL, 0, PGP_PUBRING); if (!key) return NULL; @@ -809,14 +804,11 @@ struct Body *pgp_make_key_attachment(char *tempf) static void pgp_add_string_to_hints(struct ListHead *hints, const char *str) { - char *scratch = NULL; - char *t = NULL; - - scratch = mutt_str_strdup(str); + char *scratch = mutt_str_strdup(str); if (!scratch) return; - for (t = strtok(scratch, " ,.:\"()<>\n"); t; t = strtok(NULL, " ,.:\"()<>\n")) + for (char *t = strtok(scratch, " ,.:\"()<>\n"); t; t = strtok(NULL, " ,.:\"()<>\n")) { if (strlen(t) > 3) mutt_list_insert_tail(hints, mutt_str_strdup(t)); diff --git a/ncrypt/pgpmicalg.c b/ncrypt/pgpmicalg.c index 071604801..132ba2b0c 100644 --- a/ncrypt/pgpmicalg.c +++ b/ncrypt/pgpmicalg.c @@ -158,18 +158,12 @@ static short pgp_mic_from_packet(unsigned char *p, size_t len) static short pgp_find_hash(const char *fname) { - FILE *in = NULL; - FILE *out = NULL; - char tempfile[_POSIX_PATH_MAX]; - - unsigned char *p = NULL; size_t l; - short rc = -1; mutt_mktemp(tempfile, sizeof(tempfile)); - out = mutt_file_fopen(tempfile, "w+"); + FILE *out = mutt_file_fopen(tempfile, "w+"); if (!out) { mutt_perror(tempfile); @@ -177,7 +171,7 @@ static short pgp_find_hash(const char *fname) } unlink(tempfile); - in = fopen(fname, "r"); + FILE *in = fopen(fname, "r"); if (!in) { mutt_perror(fname); @@ -187,7 +181,7 @@ static short pgp_find_hash(const char *fname) pgp_dearmor(in, out); rewind(out); - p = pgp_read_packet(out, &l); + unsigned char *p = pgp_read_packet(out, &l); if (p) { rc = pgp_mic_from_packet(p, l); diff --git a/ncrypt/pgppacket.c b/ncrypt/pgppacket.c index 001047855..1b5b8b715 100644 --- a/ncrypt/pgppacket.c +++ b/ncrypt/pgppacket.c @@ -35,12 +35,9 @@ static int read_material(size_t material, size_t *used, FILE *fp) { if (*used + material >= plen) { - unsigned char *p = NULL; - size_t nplen; + size_t nplen = *used + material + CHUNKSIZE; - nplen = *used + material + CHUNKSIZE; - - p = realloc(pbuf, nplen); + unsigned char *p = realloc(pbuf, nplen); if (!p) { perror("realloc"); diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 6245c4547..479612acd 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -484,11 +484,10 @@ static struct SmimeKey *smime_select_key(struct SmimeKey *keys, char *query) static struct SmimeKey *smime_parse_key(char *buf) { - struct SmimeKey *key = NULL; char *pend = NULL, *p = NULL; int field = 0; - key = mutt_mem_calloc(1, sizeof(struct SmimeKey)); + struct SmimeKey *key = mutt_mem_calloc(1, sizeof(struct SmimeKey)); for (p = buf; p; p = pend) { @@ -565,17 +564,14 @@ static struct SmimeKey *smime_parse_key(char *buf) static struct SmimeKey *smime_get_candidates(char *search, short public) { char index_file[_POSIX_PATH_MAX]; - FILE *fp = NULL; char buf[LONG_STRING]; - struct SmimeKey *key = NULL, *results = NULL, **results_end = NULL; - - results = NULL; - results_end = &results; + struct SmimeKey *key = NULL, *results = NULL; + struct SmimeKey **results_end = &results; snprintf(index_file, sizeof(index_file), "%s/.index", public ? NONULL(SmimeCertificates) : NONULL(SmimeKeys)); - fp = mutt_file_fopen(index_file, "r"); + FILE *fp = mutt_file_fopen(index_file, "r"); if (!fp) { mutt_perror(index_file); @@ -608,11 +604,9 @@ static struct SmimeKey *smime_get_candidates(char *search, short public) */ static struct SmimeKey *smime_get_key_by_hash(char *hash, short public) { - struct SmimeKey *results = NULL, *result = NULL; struct SmimeKey *match = NULL; - - results = smime_get_candidates(hash, public); - for (result = results; result; result = result->next) + struct SmimeKey *results = smime_get_candidates(hash, public); + for (struct SmimeKey *result = results; result; result = result->next) { if (mutt_str_strcasecmp(hash, result->hash) == 0) { @@ -769,10 +763,9 @@ static struct SmimeKey *smime_ask_for_key(char *prompt, short abilities, short p */ static void getkeys(char *mailbox) { - struct SmimeKey *key = NULL; char *k = NULL; - key = smime_get_key_by_addr(mailbox, KEYFLAG_CANENCRYPT, 0, 1); + struct SmimeKey *key = smime_get_key_by_addr(mailbox, KEYFLAG_CANENCRYPT, 0, 1); if (!key) { @@ -910,7 +903,6 @@ char *smime_find_keys(struct Address *addrlist, int oppenc_mode) static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, char ***buffer, int *num) { - FILE *fpout = NULL, *fperr = NULL; char tmpfname[_POSIX_PATH_MAX]; char email[STRING]; int rc = -1, count = 0; @@ -918,7 +910,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, size_t len = 0; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = mutt_file_fopen(tmpfname, "w+"); + FILE *fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); @@ -927,7 +919,7 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, mutt_file_unlink(tmpfname); mutt_mktemp(tmpfname, sizeof(tmpfname)); - fpout = mutt_file_fopen(tmpfname, "w+"); + FILE *fpout = mutt_file_fopen(tmpfname, "w+"); if (!fpout) { mutt_file_fclose(&fperr); @@ -1005,14 +997,13 @@ static int smime_handle_cert_email(char *certificate, char *mailbox, int copy, static char *smime_extract_certificate(char *infile) { - FILE *fpout = NULL, *fperr = NULL; char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX]; char tmpfname[_POSIX_PATH_MAX]; pid_t thepid; int empty; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = mutt_file_fopen(tmpfname, "w+"); + FILE *fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); @@ -1021,7 +1012,7 @@ static char *smime_extract_certificate(char *infile) mutt_file_unlink(tmpfname); mutt_mktemp(pk7out, sizeof(pk7out)); - fpout = mutt_file_fopen(pk7out, "w+"); + FILE *fpout = mutt_file_fopen(pk7out, "w+"); if (!fpout) { mutt_file_fclose(&fperr); @@ -1111,14 +1102,13 @@ static char *smime_extract_certificate(char *infile) static char *smime_extract_signer_certificate(char *infile) { - FILE *fpout = NULL, *fperr = NULL; char certfile[_POSIX_PATH_MAX]; char tmpfname[_POSIX_PATH_MAX]; pid_t thepid; int empty; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = mutt_file_fopen(tmpfname, "w+"); + FILE *fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); @@ -1127,7 +1117,7 @@ static char *smime_extract_signer_certificate(char *infile) mutt_file_unlink(tmpfname); mutt_mktemp(certfile, sizeof(certfile)); - fpout = mutt_file_fopen(certfile, "w+"); + FILE *fpout = mutt_file_fopen(certfile, "w+"); if (!fpout) { mutt_file_fclose(&fperr); @@ -1178,11 +1168,10 @@ static char *smime_extract_signer_certificate(char *infile) void smime_invoke_import(char *infile, char *mailbox) { char tmpfname[_POSIX_PATH_MAX], *certfile = NULL, buf[STRING]; - FILE *smimein = NULL, *fpout = NULL, *fperr = NULL; - pid_t thepid = -1; + FILE *smimein = NULL; mutt_mktemp(tmpfname, sizeof(tmpfname)); - fperr = mutt_file_fopen(tmpfname, "w+"); + FILE *fperr = mutt_file_fopen(tmpfname, "w+"); if (!fperr) { mutt_perror(tmpfname); @@ -1191,7 +1180,7 @@ void smime_invoke_import(char *infile, char *mailbox) mutt_file_unlink(tmpfname); mutt_mktemp(tmpfname, sizeof(tmpfname)); - fpout = mutt_file_fopen(tmpfname, "w+"); + FILE *fpout = mutt_file_fopen(tmpfname, "w+"); if (!fpout) { mutt_file_fclose(&fperr); @@ -1218,7 +1207,7 @@ void smime_invoke_import(char *infile, char *mailbox) { mutt_endwin(); - thepid = smime_invoke(&smimein, NULL, NULL, -1, fileno(fpout), fileno(fperr), certfile, + pid_t thepid = smime_invoke(&smimein, NULL, NULL, -1, fileno(fpout), fileno(fperr), certfile, NULL, NULL, NULL, NULL, NULL, NULL, SmimeImportCertCommand); if (thepid == -1) { @@ -1250,11 +1239,10 @@ void smime_invoke_import(char *infile, char *mailbox) int smime_verify_sender(struct Header *h) { char *mbox = NULL, *certfile = NULL, tempfname[_POSIX_PATH_MAX]; - FILE *fpout = NULL; int retval = 1; mutt_mktemp(tempfname, sizeof(tempfname)); - fpout = mutt_file_fopen(tempfname, "w"); + FILE *fpout = mutt_file_fopen(tempfname, "w"); if (!fpout) { mutt_perror(tempfname); @@ -1334,13 +1322,12 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) char tempfile[_POSIX_PATH_MAX], smimeerrfile[_POSIX_PATH_MAX]; char smimeinfile[_POSIX_PATH_MAX]; char *cert_start, *cert_end; - FILE *smimein = NULL, *smimeerr = NULL, *fpout = NULL, *fptmp = NULL; - struct Body *t = NULL; + FILE *smimein = NULL; int err = 0, empty, off; pid_t thepid; mutt_mktemp(tempfile, sizeof(tempfile)); - fpout = mutt_file_fopen(tempfile, "w+"); + FILE *fpout = mutt_file_fopen(tempfile, "w+"); if (!fpout) { mutt_perror(tempfile); @@ -1348,7 +1335,7 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) } mutt_mktemp(smimeerrfile, sizeof(smimeerrfile)); - smimeerr = mutt_file_fopen(smimeerrfile, "w+"); + FILE *smimeerr = mutt_file_fopen(smimeerrfile, "w+"); if (!smimeerr) { mutt_perror(smimeerrfile); @@ -1359,7 +1346,7 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) mutt_file_unlink(smimeerrfile); mutt_mktemp(smimeinfile, sizeof(smimeinfile)); - fptmp = mutt_file_fopen(smimeinfile, "w+"); + FILE *fptmp = mutt_file_fopen(smimeinfile, "w+"); if (!fptmp) { mutt_perror(smimeinfile); @@ -1434,7 +1421,7 @@ struct Body *smime_build_smime_entity(struct Body *a, char *certlist) return NULL; } - t = mutt_body_new(); + struct Body *t = mutt_body_new(); t->type = TYPEAPPLICATION; t->subtype = mutt_str_strdup("x-pkcs7-mime"); mutt_param_set(&t->parameter, "name", "smime.p7m"); @@ -1481,19 +1468,15 @@ static char *openssl_md_to_smime_micalg(char *md) struct Body *smime_sign_message(struct Body *a) { - struct Body *t = NULL; char buffer[LONG_STRING]; char signedfile[_POSIX_PATH_MAX], filetosign[_POSIX_PATH_MAX]; FILE *smimein = NULL, *smimeout = NULL, *smimeerr = NULL, *sfp = NULL; int err = 0; int empty = 0; pid_t thepid; - char *signas = NULL; - struct SmimeKey *signas_key = NULL; char *intermediates = NULL; - char *micalg = NULL; - signas = (SmimeSignAs && *SmimeSignAs) ? SmimeSignAs : SmimeDefaultKey; + char *signas = (SmimeSignAs && *SmimeSignAs) ? SmimeSignAs : SmimeDefaultKey; if (!signas || !*signas) { mutt_error(_("Can't sign: No key specified. Use Sign As.")); @@ -1530,7 +1513,7 @@ struct Body *smime_sign_message(struct Body *a) snprintf(SmimeCertToUse, sizeof(SmimeCertToUse), "%s/%s", NONULL(SmimeCertificates), signas); - signas_key = smime_get_key_by_hash(signas, 1); + struct SmimeKey *signas_key = smime_get_key_by_hash(signas, 1); if ((!signas_key) || (!mutt_str_strcmp("?", signas_key->issuer))) intermediates = signas; /* so openssl won't complain in any case */ else @@ -1584,7 +1567,7 @@ struct Body *smime_sign_message(struct Body *a) return NULL; /* fatal error while signing */ } - t = mutt_body_new(); + struct Body *t = mutt_body_new(); t->type = TYPEMULTIPART; t->subtype = mutt_str_strdup("signed"); t->encoding = ENC7BIT; @@ -1593,7 +1576,7 @@ struct Body *smime_sign_message(struct Body *a) mutt_generate_boundary(&t->parameter); - micalg = openssl_md_to_smime_micalg(SmimeSignDigestAlg); + char *micalg = openssl_md_to_smime_micalg(SmimeSignDigestAlg); mutt_param_set(&t->parameter, "micalg", micalg); FREE(&micalg); @@ -1641,19 +1624,18 @@ static pid_t smime_invoke_decrypt(FILE **smimein, FILE **smimeout, int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) { char signedfile[_POSIX_PATH_MAX], smimeerrfile[_POSIX_PATH_MAX]; - FILE *fp = NULL, *smimeout = NULL, *smimeerr = NULL; + FILE *smimeout = NULL; pid_t thepid; int badsig = -1; LOFF_T tmpoffset = 0; size_t tmplength = 0; int orig_type = sigbdy->type; - char *save_prefix = NULL; snprintf(signedfile, sizeof(signedfile), "%s.sig", tempfile); /* decode to a tempfile, saving the original destination */ - fp = s->fpout; + FILE *fp = s->fpout; s->fpout = mutt_file_fopen(signedfile, "w"); if (!s->fpout) { @@ -1669,7 +1651,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) /* if we are decoding binary bodies, we don't want to prefix each * line with the prefix or else the data will get corrupted. */ - save_prefix = s->prefix; + char *save_prefix = s->prefix; s->prefix = NULL; mutt_decode_attachment(sigbdy, s); @@ -1689,7 +1671,7 @@ int smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile) sigbdy->type = orig_type; mutt_mktemp(smimeerrfile, sizeof(smimeerrfile)); - smimeerr = mutt_file_fopen(smimeerrfile, "w+"); + FILE *smimeerr = mutt_file_fopen(smimeerrfile, "w+"); if (!smimeerr) { mutt_perror(smimeerrfile); diff --git a/newsrc.c b/newsrc.c index f6aed9067..b652d3fae 100644 --- a/newsrc.c +++ b/newsrc.c @@ -228,13 +228,12 @@ int nntp_newsrc_parse(struct NntpServer *nserv) 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; + char *b = NULL, *h = NULL; unsigned int j = 1; bool subs = false; - struct NntpData *nntp_data = NULL; /* find end of newsgroup name */ - p = strpbrk(line, ":!"); + char *p = strpbrk(line, ":!"); if (!p) continue; @@ -244,7 +243,7 @@ int nntp_newsrc_parse(struct NntpServer *nserv) *p++ = '\0'; /* get newsgroup data */ - nntp_data = nntp_data_find(nserv, line); + struct NntpData *nntp_data = nntp_data_find(nserv, line); FREE(&nntp_data->newsrc_ent); /* count number of entries */ @@ -587,11 +586,10 @@ static int active_get_cache(struct NntpServer *nserv) char buf[HUGE_STRING]; char file[_POSIX_PATH_MAX]; time_t t; - FILE *fp = NULL; cache_expand(file, sizeof(file), &nserv->conn->account, ".active"); mutt_debug(1, "Parsing %s\n", file); - fp = mutt_file_fopen(file, "r"); + FILE *fp = mutt_file_fopen(file, "r"); if (!fp) return -1; diff --git a/nntp.c b/nntp.c index 6789affaa..3f2f7b3ed 100644 --- a/nntp.c +++ b/nntp.c @@ -943,13 +943,11 @@ static int fetch_description(char *line, void *data) */ static int get_description(struct NntpData *nntp_data, char *wildmat, char *msg) { - struct NntpServer *nserv = NULL; char buf[STRING]; char *cmd = NULL; - int rc; /* get newsgroup description, if possible */ - nserv = nntp_data->nserv; + struct NntpServer *nserv = nntp_data->nserv; if (!wildmat) wildmat = nntp_data->group; if (nserv->hasLIST_NEWSGROUPS) @@ -960,7 +958,7 @@ static int get_description(struct NntpData *nntp_data, char *wildmat, char *msg) return 0; snprintf(buf, sizeof(buf), "%s %s\r\n", cmd, wildmat); - rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), msg, fetch_description, nserv); + int rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), msg, fetch_description, nserv); if (rc > 0) { mutt_error("%s: %s", cmd, buf); @@ -976,17 +974,16 @@ static int get_description(struct NntpData *nntp_data, char *wildmat, char *msg) static void nntp_parse_xref(struct Context *ctx, struct Header *hdr) { struct NntpData *nntp_data = ctx->data; - char *buf = NULL, *p = NULL; - buf = p = mutt_str_strdup(hdr->env->xref); + char *buf = mutt_str_strdup(hdr->env->xref); + char *p = buf; while (p) { - char *grp = NULL, *colon = NULL; anum_t anum; /* skip to next word */ p += strspn(p, " \t"); - grp = p; + char *grp = p; /* skip to end of word */ p = strpbrk(p, " \t"); @@ -994,7 +991,7 @@ static void nntp_parse_xref(struct Context *ctx, struct Header *hdr) *p++ = '\0'; /* find colon */ - colon = strchr(grp, ':'); + char *colon = strchr(grp, ':'); if (!colon) continue; *colon++ = '\0'; @@ -1144,12 +1141,11 @@ static int parse_overview_line(char *line, void *data) #ifdef USE_HCACHE if (fc->hc) { - void *hdata = NULL; char buf[16]; /* try to replace with header from cache */ snprintf(buf, sizeof(buf), "%d", anum); - hdata = mutt_hcache_fetch(fc->hc, buf, strlen(buf)); + void *hdata = mutt_hcache_fetch(fc->hc, buf, strlen(buf)); if (hdata) { mutt_debug(2, "mutt_hcache_fetch %s\n", buf); @@ -1346,11 +1342,10 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, /* fetch header from server */ else { - FILE *fp = NULL; char tempfile[_POSIX_PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); - fp = mutt_file_fopen(tempfile, "w+"); + FILE *fp = mutt_file_fopen(tempfile, "w+"); if (!fp) { mutt_perror(tempfile); @@ -1877,7 +1872,6 @@ static int check_mailbox(struct Context *ctx) /* .newsrc has been externally modified */ if (nserv->newsrc_modified) { - anum_t anum; #ifdef USE_HCACHE unsigned char *messages = NULL; char buf[16]; @@ -1894,6 +1888,7 @@ static int check_mailbox(struct Context *ctx) /* update flags according to .newsrc */ int j = 0; + anum_t anum; for (int i = 0; i < ctx->msgcount; i++) { bool flagged = false; @@ -2358,14 +2353,11 @@ int nntp_check_new_groups(struct NntpServer *nserv) int nntp_check_msgid(struct Context *ctx, const char *msgid) { struct NntpData *nntp_data = ctx->data; - struct Header *hdr = NULL; - FILE *fp = NULL; char tempfile[_POSIX_PATH_MAX]; char buf[LONG_STRING]; - int rc; mutt_mktemp(tempfile, sizeof(tempfile)); - fp = mutt_file_fopen(tempfile, "w+"); + FILE *fp = mutt_file_fopen(tempfile, "w+"); if (!fp) { mutt_perror(tempfile); @@ -2374,7 +2366,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) } snprintf(buf, sizeof(buf), "HEAD %s\r\n", msgid); - rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), NULL, fetch_tempfile, fp); + int rc = nntp_fetch_lines(nntp_data, buf, sizeof(buf), NULL, fetch_tempfile, fp); if (rc) { mutt_file_fclose(&fp); @@ -2390,7 +2382,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) /* parse header */ if (ctx->msgcount == ctx->hdrmax) mx_alloc_memory(ctx); - hdr = ctx->hdrs[ctx->msgcount] = mutt_header_new(); + struct Header *hdr = ctx->hdrs[ctx->msgcount] = mutt_header_new(); hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); hdr->env = mutt_rfc822_read_header(fp, hdr, 0, 0); mutt_file_fclose(&fp); diff --git a/pager.c b/pager.c index 2daac8bda..0508c7f7e 100644 --- a/pager.c +++ b/pager.c @@ -378,9 +378,7 @@ static void new_class_color(struct QClass *class, int *q_level) static void shift_class_colors(struct QClass *quote_list, struct QClass *new_class, int index, int *q_level) { - struct QClass *q_list = NULL; - - q_list = quote_list; + struct QClass *q_list = quote_list; new_class->index = -1; while (q_list) diff --git a/parse.c b/parse.c index 5b04b120f..212e9ebdb 100644 --- a/parse.c +++ b/parse.c @@ -292,14 +292,11 @@ int mutt_check_mime_type(const char *s) void mutt_parse_content_type(char *s, struct Body *ct) { - char *pc = NULL; - char *subtype = NULL; - FREE(&ct->subtype); mutt_param_free(&ct->parameter); /* First extract any existing parameters */ - pc = strchr(s, ';'); + char *pc = strchr(s, ';'); if (pc) { *pc++ = 0; @@ -323,7 +320,7 @@ void mutt_parse_content_type(char *s, struct Body *ct) } /* Now get the subtype */ - subtype = strchr(s, '/'); + char *subtype = strchr(s, '/'); if (subtype) { *subtype++ = '\0'; @@ -542,12 +539,10 @@ void mutt_parse_part(FILE *fp, struct Body *b) */ struct Body *mutt_rfc822_parse_message(FILE *fp, struct Body *parent) { - struct Body *msg = NULL; - parent->hdr = mutt_header_new(); parent->hdr->offset = ftello(fp); parent->hdr->env = mutt_rfc822_read_header(fp, parent->hdr, 0, 0); - msg = parent->hdr->content; + struct Body *msg = parent->hdr->content; /* ignore the length given in the content-length since it could be wrong and we already have the info to calculate the correct length */ diff --git a/pattern.c b/pattern.c index 680b42aa3..c8b986d4c 100644 --- a/pattern.c +++ b/pattern.c @@ -78,10 +78,9 @@ static bool eat_regex(struct Pattern *pat, struct Buffer *s, struct Buffer *err) struct Buffer buf; char errmsg[STRING]; int r; - char *pexpr = NULL; mutt_buffer_init(&buf); - pexpr = s->dptr; + char *pexpr = s->dptr; if (mutt_extract_token(&buf, s, MUTT_TOKEN_PATTERN | MUTT_TOKEN_COMMENT) != 0 || !buf.data) { snprintf(err->data, err->dsize, _("Error in expression: %s"), pexpr); @@ -398,10 +397,9 @@ static bool eat_date(struct Pattern *pat, struct Buffer *s, struct Buffer *err) { struct Buffer buffer; struct tm min, max; - char *pexpr = NULL; mutt_buffer_init(&buffer); - pexpr = s->dptr; + char *pexpr = s->dptr; if (mutt_extract_token(&buffer, s, MUTT_TOKEN_COMMENT | MUTT_TOKEN_PATTERN) != 0 || !buffer.data) { @@ -631,7 +629,6 @@ static int report_regerror(int regerr, regex_t *preg, struct Buffer *err) static bool is_context_available(struct Buffer *s, regmatch_t pmatch[], int kind, struct Buffer *err) { - char *context_loc = NULL; const char *context_req_chars[] = { [RANGE_K_REL] = ".0123456789", [RANGE_K_ABS] = ".", @@ -643,7 +640,7 @@ static bool is_context_available(struct Buffer *s, regmatch_t pmatch[], /* First decide if we're going to need the context at all. * Relative patterns need it iff they contain a dot or a number. * Absolute patterns only need it if they contain a dot. */ - context_loc = strpbrk(s->dptr + pmatch[0].rm_so, context_req_chars[kind]); + char *context_loc = strpbrk(s->dptr + pmatch[0].rm_so, context_req_chars[kind]); if (!context_loc || (context_loc >= &s->dptr[pmatch[0].rm_eo])) return true; diff --git a/pgppubring.c b/pgppubring.c index 4b469d949..85ded0769 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -221,9 +221,8 @@ static void pgp_make_pgp2_fingerprint(unsigned char *buf, unsigned char *digest) static char *binary_fingerprint_to_string(unsigned char *buf, size_t length) { - char *fingerprint = NULL, *pf = NULL; - - pf = fingerprint = mutt_mem_malloc((length * 2) + 1); + char *fingerprint = mutt_mem_malloc((length * 2) + 1); + char *pf = fingerprint; for (size_t i = 0; i < length; i++) { @@ -343,7 +342,6 @@ static void skip_bignum(unsigned char *buf, size_t l, size_t j, size_t *toff, si static struct PgpKeyInfo *pgp_parse_pgp3_key(unsigned char *buf, size_t l) { - struct PgpKeyInfo *p = NULL; unsigned char alg; unsigned char digest[SHA_DIGEST_LENGTH]; unsigned char scratch[LONG_STRING]; @@ -353,7 +351,7 @@ static struct PgpKeyInfo *pgp_parse_pgp3_key(unsigned char *buf, size_t l) short len; size_t j; - p = pgp_new_keyinfo(); + struct PgpKeyInfo *p = pgp_new_keyinfo(); j = 2; for (i = 0; i < 4; i++) @@ -763,11 +761,8 @@ static void pgpring_find_candidates(char *ringfile, const char *hints[], int nhi FILE *rfp = fopen(ringfile, "r"); if (!rfp) { - char *error_buf = NULL; - size_t error_buf_len; - - error_buf_len = sizeof("fopen: ") - 1 + strlen(ringfile) + 1; - error_buf = mutt_mem_malloc(error_buf_len); + size_t error_buf_len = sizeof("fopen: ") - 1 + strlen(ringfile) + 1; + char *error_buf = mutt_mem_malloc(error_buf_len); snprintf(error_buf, error_buf_len, "fopen: %s", ringfile); perror(error_buf); FREE(&error_buf); @@ -797,13 +792,11 @@ static void pgpring_find_candidates(char *ringfile, const char *hints[], int nhi if (pgpring_string_matches_hint(tmp, hints, nhints)) { - struct PgpKeyInfo *p = NULL; - fsetpos(rfp, &keypos); /* Not bailing out here would lead us into an endless loop. */ - p = pgp_parse_keyblock(rfp); + struct PgpKeyInfo *p = pgp_parse_keyblock(rfp); if (!p) err = 1; diff --git a/pop.c b/pop.c index 8330b6681..0b92ca9e1 100644 --- a/pop.c +++ b/pop.c @@ -82,14 +82,13 @@ static int fetch_message(char *line, void *file) */ static int pop_read_header(struct PopData *pop_data, struct Header *h) { - FILE *f = NULL; int rc, index; size_t length; char buf[LONG_STRING]; char tempfile[_POSIX_PATH_MAX]; mutt_mktemp(tempfile, sizeof(tempfile)); - f = mutt_file_fopen(tempfile, "w+"); + FILE *f = mutt_file_fopen(tempfile, "w+"); if (!f) { mutt_perror(tempfile); @@ -201,13 +200,10 @@ static int fetch_uidl(char *line, void *data) static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data) { - struct Context *ctx = NULL; - struct PopData *pop_data = NULL; - - ctx = (struct Context *) data; + struct Context *ctx = (struct Context *) data; if (!ctx) return -1; - pop_data = (struct PopData *) ctx->data; + struct PopData *pop_data = (struct PopData *) ctx->data; if (!pop_data) return -1; diff --git a/pop_lib.c b/pop_lib.c index 7c1c3318c..b5ad8b105 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -55,15 +55,13 @@ int pop_parse_path(const char *path, struct Account *acct) { struct Url url; - char *c = NULL; - struct servent *service = NULL; /* Defaults */ acct->flags = 0; acct->type = MUTT_ACCT_TYPE_POP; acct->port = 0; - c = mutt_str_strdup(path); + char *c = mutt_str_strdup(path); url_parse(&url, c); if ((url.scheme != U_POP && url.scheme != U_POPS) || !url.host || @@ -78,7 +76,7 @@ int pop_parse_path(const char *path, struct Account *acct) if (url.scheme == U_POPS) acct->flags |= MUTT_ACCT_SSL; - service = getservbyname(url.scheme == U_POP ? "pop3" : "pop3s", "tcp"); + struct servent *service = getservbyname(url.scheme == U_POP ? "pop3" : "pop3s", "tcp"); if (!acct->port) { if (service) @@ -100,14 +98,12 @@ int pop_parse_path(const char *path, struct Account *acct) */ static void pop_error(struct PopData *pop_data, char *msg) { - char *t = NULL, *c = NULL, *c2 = NULL; - - t = strchr(pop_data->err_msg, '\0'); - c = msg; + char *t = strchr(pop_data->err_msg, '\0'); + char *c = msg; if (mutt_str_strncmp(msg, "-ERR ", 5) == 0) { - c2 = mutt_str_skip_email_wsp(msg + 5); + char *c2 = mutt_str_skip_email_wsp(msg + 5); if (*c2) c = c2; diff --git a/query.c b/query.c index 189d4c1ec..a0057b4d7 100644 --- a/query.c +++ b/query.c @@ -356,9 +356,7 @@ static void query_menu(char *buf, size_t buflen, struct Query *results, int retb case OP_QUERY: if (mutt_get_field(_("Query: "), buf, buflen, 0) == 0 && buf[0]) { - struct Query *newresults = NULL; - - newresults = run_query(buf, 0); + struct Query *newresults = run_query(buf, 0); menu->redraw = REDRAW_FULL; if (newresults) diff --git a/recvattach.c b/recvattach.c index 514c639cc..093cb901f 100644 --- a/recvattach.c +++ b/recvattach.c @@ -712,7 +712,6 @@ void mutt_pipe_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, { struct State state; char buf[SHORT_STRING]; - pid_t thepid; if (fp) filter = false; /* sanity check: we can't filter in the recv case yet */ @@ -732,7 +731,7 @@ void mutt_pipe_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, if (!filter && !AttachSplit) { mutt_endwin(); - thepid = mutt_create_filter(buf, &state.fpout, NULL, NULL); + pid_t thepid = mutt_create_filter(buf, &state.fpout, NULL, NULL); pipe_attachment_list(buf, actx, fp, tag, top, filter, &state); mutt_file_fclose(&state.fpout); if (mutt_wait_filter(thepid) != 0 || WaitKey) @@ -835,7 +834,6 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru { struct State state = { 0 }; - pid_t thepid; if (query_quadoption(Print, tag ? _("Print tagged attachment(s)?") : _("Print attachment?")) != MUTT_YES) return; @@ -845,7 +843,7 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru if (!can_print(actx, top, tag)) return; mutt_endwin(); - thepid = mutt_create_filter(NONULL(PrintCommand), &state.fpout, NULL, NULL); + pid_t thepid = mutt_create_filter(NONULL(PrintCommand), &state.fpout, NULL, NULL); print_attachment_list(actx, fp, tag, top, &state); mutt_file_fclose(&state.fpout); if (mutt_wait_filter(thepid) != 0 || WaitKey) @@ -1153,10 +1151,7 @@ static const char *Function_not_permitted = void mutt_view_attachments(struct Header *hdr) { char helpstr[LONG_STRING]; - struct Menu *menu = NULL; struct Body *cur = NULL; - struct Message *msg = NULL; - struct AttachCtx *actx = NULL; int flags = 0; int op = OP_NULL; @@ -1165,18 +1160,18 @@ void mutt_view_attachments(struct Header *hdr) mutt_message_hook(Context, hdr, MUTT_MESSAGEHOOK); - msg = mx_open_message(Context, hdr->msgno); + struct Message *msg = mx_open_message(Context, hdr->msgno); if (!msg) return; - menu = mutt_menu_new(MENU_ATTACH); + struct Menu *menu = mutt_menu_new(MENU_ATTACH); menu->title = _("Attachments"); menu->make_entry = attach_entry; menu->tag = mutt_tag_attach; menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_ATTACH, AttachHelp); mutt_menu_push_current(menu); - actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1); + struct AttachCtx *actx = mutt_mem_calloc(sizeof(struct AttachCtx), 1); actx->hdr = hdr; actx->root_fp = msg->fp; mutt_update_recvattach_menu(actx, menu, 1); diff --git a/recvcmd.c b/recvcmd.c index 45e42542b..a394801dc 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -378,18 +378,11 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx { bool mime_fwd_all = false; bool mime_fwd_any = true; - struct AttachPtr *parent = NULL; struct Header *parent_hdr = NULL; FILE *parent_fp = NULL; - struct Header *tmphdr = NULL; - struct Body **last = NULL; char tmpbody[_POSIX_PATH_MAX]; - FILE *tmpfp = NULL; - char prefix[STRING]; - int rc = 0; - struct State st; /* @@ -398,7 +391,7 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx * putting the following lines into an if block. */ - parent = find_parent(actx, cur, nattach); + struct AttachPtr *parent = find_parent(actx, cur, nattach); if (parent) { parent_hdr = parent->content->hdr; @@ -410,12 +403,12 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx parent_fp = actx->root_fp; } - tmphdr = mutt_header_new(); + struct Header *tmphdr = mutt_header_new(); tmphdr->env = mutt_env_new(); mutt_make_forward_subject(tmphdr->env, Context, parent_hdr); mutt_mktemp(tmpbody, sizeof(tmpbody)); - tmpfp = mutt_file_fopen(tmpbody, "w"); + FILE *tmpfp = mutt_file_fopen(tmpbody, "w"); if (!tmpfp) { mutt_error(_("Can't open temporary file %s."), tmpbody); @@ -484,7 +477,7 @@ static void attach_forward_bodies(FILE *fp, struct Header *hdr, struct AttachCtx st.fpout = tmpfp; /* where do we append new MIME parts? */ - last = &tmphdr->content; + struct Body **last = &tmphdr->content; if (cur) { diff --git a/remailer.c b/remailer.c index a9afcd83c..7e9f61959 100644 --- a/remailer.c +++ b/remailer.c @@ -479,11 +479,8 @@ static const struct Mapping RemailerHelp[] = { void mix_make_chain(struct ListHead *chainhead) { - struct MixChain *chain = NULL; int c_cur = 0, c_old = 0; bool c_redraw = true; - - struct Remailer **type2_list = NULL; size_t ttll = 0; struct Coord *coords = NULL; @@ -494,14 +491,14 @@ void mix_make_chain(struct ListHead *chainhead) char *t = NULL; - type2_list = mix_type2_list(&ttll); + struct Remailer **type2_list = mix_type2_list(&ttll); if (!type2_list) { mutt_error(_("Can't get mixmaster's type2.list!")); return; } - chain = mutt_mem_calloc(1, sizeof(struct MixChain)); + struct MixChain *chain = mutt_mem_calloc(1, sizeof(struct MixChain)); struct ListNode *p; STAILQ_FOREACH(p, chainhead, entries) diff --git a/rfc1524.c b/rfc1524.c index 63bc679e0..b44a9fb47 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -175,7 +175,6 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, struct Rfc1524MailcapEntry *entry, int opt) { char *buf = NULL; - char *ch = NULL; int found = false; int line = 0; @@ -191,7 +190,7 @@ static int rfc1524_mailcap_parse(struct Body *a, char *filename, char *type, */ /* find length of basetype */ - ch = strchr(type, '/'); + char *ch = strchr(type, '/'); if (!ch) return false; const int btlen = ch - type; diff --git a/rfc2231.c b/rfc2231.c index 8c774a486..a5ef37b5d 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -65,9 +65,7 @@ static void purge_empty_parameters(struct ParameterList *p) static char *rfc2231_get_charset(char *value, char *charset, size_t chslen) { - char *t = NULL, *u = NULL; - - t = strchr(value, '\''); + char *t = strchr(value, '\''); if (!t) { charset[0] = '\0'; @@ -77,7 +75,7 @@ static char *rfc2231_get_charset(char *value, char *charset, size_t chslen) *t = '\0'; mutt_str_strfcpy(charset, value, chslen); - u = strchr(t + 1, '\''); + char *u = strchr(t + 1, '\''); if (u) return u + 1; else diff --git a/rfc3676.c b/rfc3676.c index 32e6b3fa9..b35e2ef4a 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -267,7 +267,7 @@ static void print_fixed_line(const char *line, struct State *s, int ql, struct F */ int rfc3676_handler(struct Body *a, struct State *s) { - char *buf = NULL, *t = NULL; + char *buf = NULL; unsigned int quotelevel = 0; int delsp = 0; size_t sz = 0; @@ -276,7 +276,7 @@ int rfc3676_handler(struct Body *a, struct State *s) memset(&fst, 0, sizeof(fst)); /* respect DelSp of RFC3676 only with f=f parts */ - t = mutt_param_get(&a->parameter, "delsp"); + char *t = mutt_param_get(&a->parameter, "delsp"); if (t) { delsp = mutt_str_strlen(t) == 3 && (mutt_str_strncasecmp(t, "yes", 3) == 0); diff --git a/send.c b/send.c index 8da3b80c1..e0959cb65 100644 --- a/send.c +++ b/send.c @@ -85,9 +85,9 @@ static void append_signature(FILE *f) */ struct Address *mutt_remove_xrefs(struct Address *a, struct Address *b) { - struct Address *top = NULL, *p = NULL, *prev = NULL; + struct Address *p = NULL, *prev = NULL; - top = b; + struct Address *top = b; while (b) { for (p = a; p; p = p->next) @@ -1057,7 +1057,6 @@ struct Address *mutt_default_from(void) static int send_message(struct Header *msg) { char tempfile[_POSIX_PATH_MAX]; - FILE *tempfp = NULL; int i; #ifdef USE_SMTP short old_write_bcc; @@ -1065,7 +1064,7 @@ static int send_message(struct Header *msg) /* Write out the message in MIME form. */ mutt_mktemp(tempfile, sizeof(tempfile)); - tempfp = mutt_file_fopen(tempfile, "w"); + FILE *tempfp = mutt_file_fopen(tempfile, "w"); if (!tempfp) return -1; @@ -1154,9 +1153,7 @@ static void decode_descriptions(struct Body *b) static void fix_end_of_file(const char *data) { - FILE *fp = NULL; - - fp = mutt_file_fopen(data, "a+"); + FILE *fp = mutt_file_fopen(data, "a+"); if (!fp) return; if (fseek(fp, -1, SEEK_END) >= 0) @@ -1232,7 +1229,8 @@ static int is_reply(struct Header *reply, struct Header *orig) static bool search_attach_keyword(char *filename) { /* Search for the regex in AbortNoattachRegex within a file */ - if (!AbortNoattachRegex || !AbortNoattachRegex->regex || !QuoteRegex || !QuoteRegex->regex) + if (!AbortNoattachRegex || !AbortNoattachRegex->regex || !QuoteRegex || + !QuoteRegex->regex) return false; FILE *attf = mutt_file_fopen(filename, "r"); @@ -1886,8 +1884,9 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, #ifdef USE_NNTP if (!(flags & SENDNEWS)) #endif - if (!mutt_addr_has_recips(msg->env->to) && !mutt_addr_has_recips(msg->env->cc) && - !mutt_addr_has_recips(msg->env->bcc)) + if ((mutt_addr_has_recips(msg->env->to) == 0) && + (mutt_addr_has_recips(msg->env->cc) == 0) && + (mutt_addr_has_recips(msg->env->bcc) == 0)) { if (!(flags & SENDBATCH)) { @@ -1933,18 +1932,17 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile, } #endif - if (!(flags & SENDBATCH) && - (AbortNoattach != MUTT_NO) && !msg->content->next && - (msg->content->type == TYPETEXT) && - (mutt_str_strcasecmp (msg->content->subtype, "plain") == 0) && + if (!(flags & SENDBATCH) && (AbortNoattach != MUTT_NO) && + !msg->content->next && (msg->content->type == TYPETEXT) && + (mutt_str_strcasecmp(msg->content->subtype, "plain") == 0) && search_attach_keyword(msg->content->filename) && query_quadoption(AbortNoattach, _("No attachments, cancel sending?")) != MUTT_NO) { /* if the abort is automatic, print an error message */ if (AbortNoattach == MUTT_YES) { - mutt_error(_( - "Message contains text matching \"$abort_noattach_regex\". Not sending.")); + mutt_error(_("Message contains text matching " + "\"$abort_noattach_regex\". Not sending.")); } goto main_loop; } diff --git a/sendlib.c b/sendlib.c index dd082daf8..0e2b865c7 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1463,10 +1463,7 @@ static void run_mime_type_query(struct Body *att) struct Body *mutt_make_file_attach(const char *path) { - struct Body *att = NULL; - struct Content *info = NULL; - - att = mutt_body_new(); + struct Body *att = mutt_body_new(); att->filename = mutt_str_strdup(path); if (MimeTypeQueryCommand && *MimeTypeQueryCommand && MimeTypeQueryFirst) @@ -1483,7 +1480,7 @@ struct Body *mutt_make_file_attach(const char *path) run_mime_type_query(att); } - info = mutt_get_content_info(path, att); + struct Content *info = mutt_get_content_info(path, att); if (!info) { mutt_body_free(&att); @@ -1553,9 +1550,7 @@ static bool check_boundary(const char *boundary, struct Body *b) struct Body *mutt_make_multipart(struct Body *b) { - struct Body *new = NULL; - - new = mutt_body_new(); + struct Body *new = mutt_body_new(); new->type = TYPEMULTIPART; new->subtype = mutt_str_strdup("mixed"); new->encoding = get_toplevel_encoding(b); @@ -2237,15 +2232,13 @@ static char *gen_msgid(void) { char buf[SHORT_STRING]; time_t now; - struct tm *tm = NULL; - const char *fqdn = NULL; unsigned char rndid[MUTT_RANDTAG_LEN + 1]; mutt_rand_base32(rndid, sizeof(rndid) - 1); rndid[MUTT_RANDTAG_LEN] = 0; now = time(NULL); - tm = gmtime(&now); - fqdn = mutt_fqdn(0); + struct tm *tm = gmtime(&now); + const char *fqdn = mutt_fqdn(0); if (!fqdn) fqdn = NONULL(ShortHostname); @@ -2272,8 +2265,7 @@ static void alarm_handler(int sig) static int send_msg(const char *path, char **args, const char *msg, char **tempfile) { sigset_t set; - int fd, st; - pid_t pid, ppid; + int st; mutt_sig_block_system(); @@ -2290,13 +2282,13 @@ static int send_msg(const char *path, char **args, const char *msg, char **tempf *tempfile = mutt_str_strdup(tmp); } - pid = fork(); + pid_t pid = fork(); if (pid == 0) { struct sigaction act, oldalrm; /* save parent's ID before setsid() */ - ppid = getppid(); + pid_t ppid = getppid(); /* we want the delivery to continue even after the main process dies, * so we put ourselves into another session right away @@ -2306,10 +2298,10 @@ static int send_msg(const char *path, char **args, const char *msg, char **tempf /* next we close all open files */ close(0); #ifdef OPEN_MAX - for (fd = tempfile ? 1 : 3; fd < OPEN_MAX; fd++) + for (int fd = tempfile ? 1 : 3; fd < OPEN_MAX; fd++) close(fd); #elif defined(_POSIX_OPEN_MAX) - for (fd = tempfile ? 1 : 3; fd < _POSIX_OPEN_MAX; fd++) + for (int fd = tempfile ? 1 : 3; fd < _POSIX_OPEN_MAX; fd++) close(fd); #else if (tempfile) @@ -2600,9 +2592,7 @@ int mutt_invoke_sendmail(struct Address *from, struct Address *to, struct Addres { if (i != S_BKG) { - const char *e = NULL; - - e = mutt_str_sysexit(i); + const char *e = mutt_str_sysexit(i); mutt_error(_("Error sending message, child exited %d (%s)."), i, NONULL(e)); if (childout) { @@ -2769,14 +2759,13 @@ static int bounce_message(FILE *fp, struct Header *h, struct Address *to, int mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to) { - struct Address *from = NULL, *resent_to = NULL; const char *fqdn = mutt_fqdn(1); char resent_from[STRING]; int ret; char *err = NULL; resent_from[0] = '\0'; - from = mutt_default_from(); + struct Address *from = mutt_default_from(); /* * mutt_default_from() does not use $realname if the real name is not set @@ -2809,7 +2798,7 @@ int mutt_bounce_message(FILE *fp, struct Header *h, struct Address *to) * function is called, since the user receives confirmation of the address * list being bounced to. */ - resent_to = mutt_addr_copy_list(to, false); + struct Address *resent_to = mutt_addr_copy_list(to, false); rfc2047_encode_addrlist(resent_to, "Resent-To"); ret = bounce_message(fp, h, resent_to, resent_from, from); @@ -2889,18 +2878,16 @@ int mutt_write_multiple_fcc(const char *path, struct Header *hdr, const char *ms { char fcc_tok[_POSIX_PATH_MAX]; char fcc_expanded[_POSIX_PATH_MAX]; - char *tok = NULL; - int status; mutt_str_strfcpy(fcc_tok, path, sizeof(fcc_tok)); - tok = strtok(fcc_tok, ","); + char *tok = strtok(fcc_tok, ","); if (!tok) return -1; mutt_debug(1, "Fcc: initial mailbox = '%s'\n", tok); /* mutt_expand_path already called above for the first token */ - status = mutt_write_fcc(tok, hdr, msgid, post, fcc, finalpath); + int status = mutt_write_fcc(tok, hdr, msgid, post, fcc, finalpath); if (status != 0) return status; diff --git a/sidebar.c b/sidebar.c index 3567cac02..08964d99f 100644 --- a/sidebar.c +++ b/sidebar.c @@ -916,9 +916,8 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) } else if (maildir_is_prefix && SidebarFolderIndent) { - const char *tmp_folder_name = NULL; int lastsep = 0; - tmp_folder_name = b->path + maildirlen + 1; + const char *tmp_folder_name = b->path + maildirlen + 1; int tmplen = (int) mutt_str_strlen(tmp_folder_name) - 1; for (int i = 0; i < tmplen; i++) { diff --git a/smtp.c b/smtp.c index 0707a4bad..42a28a375 100644 --- a/smtp.c +++ b/smtp.c @@ -173,13 +173,12 @@ static int smtp_rcpt_to(struct Connection *conn, const struct Address *a) static int smtp_data(struct Connection *conn, const char *msgfile) { char buf[1024]; - FILE *fp = NULL; struct Progress progress; struct stat st; int r, term = 0; size_t buflen = 0; - fp = fopen(msgfile, "r"); + FILE *fp = fopen(msgfile, "r"); if (!fp) { mutt_error(_("SMTP session failed: unable to open %s"), msgfile); diff --git a/sort.c b/sort.c index 008d0ea10..c75c19878 100644 --- a/sort.c +++ b/sort.c @@ -131,12 +131,10 @@ static int compare_to(const void *a, const void *b) struct Header **ppa = (struct Header **) a; struct Header **ppb = (struct Header **) b; char fa[SHORT_STRING]; - const char *fb = NULL; - int result; mutt_str_strfcpy(fa, mutt_get_name((*ppa)->env->to), SHORT_STRING); - fb = mutt_get_name((*ppb)->env->to); - result = mutt_str_strncasecmp(fa, fb, SHORT_STRING); + const char *fb = mutt_get_name((*ppb)->env->to); + int result = mutt_str_strncasecmp(fa, fb, SHORT_STRING); result = perform_auxsort(result, a, b); return (SORTCODE(result)); } @@ -146,12 +144,10 @@ static int compare_from(const void *a, const void *b) struct Header **ppa = (struct Header **) a; struct Header **ppb = (struct Header **) b; char fa[SHORT_STRING]; - const char *fb = NULL; - int result; mutt_str_strfcpy(fa, mutt_get_name((*ppa)->env->from), SHORT_STRING); - fb = mutt_get_name((*ppb)->env->from); - result = mutt_str_strncasecmp(fa, fb, SHORT_STRING); + const char *fb = mutt_get_name((*ppb)->env->from); + int result = mutt_str_strncasecmp(fa, fb, SHORT_STRING); result = perform_auxsort(result, a, b); return (SORTCODE(result)); } diff --git a/thread.c b/thread.c index 353631791..f8596d2c7 100644 --- a/thread.c +++ b/thread.c @@ -507,14 +507,11 @@ static void insert_message(struct MuttThread **new, static struct Hash *make_subj_hash(struct Context *ctx) { - struct Header *hdr = NULL; - struct Hash *hash = NULL; - - hash = mutt_hash_create(ctx->msgcount * 2, MUTT_HASH_ALLOW_DUPS); + struct Hash *hash = mutt_hash_create(ctx->msgcount * 2, MUTT_HASH_ALLOW_DUPS); for (int i = 0; i < ctx->msgcount; i++) { - hdr = ctx->hdrs[i]; + struct Header *hdr = ctx->hdrs[i]; if (hdr->env->real_subj) mutt_hash_insert(hash, hdr->env->real_subj, hdr); } @@ -1390,14 +1387,11 @@ int mutt_messages_in_thread(struct Context *ctx, struct Header *hdr, int flag) struct Hash *mutt_make_id_hash(struct Context *ctx) { - struct Header *hdr = NULL; - struct Hash *hash = NULL; - - hash = mutt_hash_create(ctx->msgcount * 2, 0); + struct Hash *hash = mutt_hash_create(ctx->msgcount * 2, 0); for (int i = 0; i < ctx->msgcount; i++) { - hdr = ctx->hdrs[i]; + struct Header *hdr = ctx->hdrs[i]; if (hdr->env->message_id) mutt_hash_insert(hash, hdr->env->message_id, hdr); } diff --git a/url.c b/url.c index 186dfbb80..b20f5e096 100644 --- a/url.c +++ b/url.c @@ -348,23 +348,21 @@ int url_tostring(struct Url *u, char *dest, size_t len, int flags) int url_parse_mailto(struct Envelope *e, char **body, const char *src) { - char *t = NULL, *p = NULL; - char *tmp = NULL; - char *headers = NULL; + char *p = NULL; char *tag = NULL, *value = NULL; int rc = -1; - t = strchr(src, ':'); + char *t = strchr(src, ':'); if (!t) return -1; /* copy string for safe use of strtok() */ - tmp = mutt_str_strdup(t + 1); + char *tmp = mutt_str_strdup(t + 1); if (!tmp) return -1; - headers = strchr(tmp, '?'); + char *headers = strchr(tmp, '?'); if (headers) *headers++ = '\0'; diff --git a/version.c b/version.c index a9a72d623..52ef2574c 100644 --- a/version.c +++ b/version.c @@ -334,9 +334,7 @@ static char *rstrip_in_place(char *s) if (!s) return NULL; - char *p = NULL; - - p = &s[strlen(s)]; + char *p = &s[strlen(s)]; if (p == s) return s; p--;