From: Richard Russon Date: Sat, 31 Aug 2019 18:21:49 +0000 (+0100) Subject: tidy code X-Git-Tag: 2019-10-25~63^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82153f4d8fc33899628f90537635ca1649201c4e;p=neomutt tidy code - rename variables: b to buf - fix Buffer check - remove redundant conditionals --- diff --git a/compose.c b/compose.c index 079ba0bb2..34b8d926f 100644 --- a/compose.c +++ b/compose.c @@ -527,6 +527,7 @@ static void update_crypt_info(struct ComposeRedrawData *rd) /** * redraw_mix_line - Redraw the Mixmaster chain * @param chain List of chain links + * @param rd Email and other compose data */ static void redraw_mix_line(struct ListHead *chain, struct ComposeRedrawData *rd) { diff --git a/email/rfc2047.c b/email/rfc2047.c index a0ae382c3..0fdaa634c 100644 --- a/email/rfc2047.c +++ b/email/rfc2047.c @@ -683,7 +683,7 @@ void rfc2047_decode(char **pd) } /* If we have some previously decoded text, add it now */ - if (prev.data) + if (!mutt_buffer_is_empty(&prev)) { finalize_chunk(&buf, &prev, prev_charset, prev_charsetlen); } diff --git a/hcache/serialize.c b/hcache/serialize.c index 4f48f392f..9f5d59e6d 100644 --- a/hcache/serialize.c +++ b/hcache/serialize.c @@ -298,15 +298,15 @@ void serial_restore_stailq(struct ListHead *l, const unsigned char *d, int *off, /** * serial_dump_buffer - Pack a Buffer into a binary blob - * @param b Buffer to pack + * @param buf Buffer to pack * @param d Binary blob to add to * @param off Offset into the blob * @param convert If true, the strings will be converted to utf-8 * @retval ptr End of the newly packed binary */ -unsigned char *serial_dump_buffer(struct Buffer *b, unsigned char *d, int *off, bool convert) +unsigned char *serial_dump_buffer(struct Buffer *buf, unsigned char *d, int *off, bool convert) { - if (!b) + if (!buf) { d = serial_dump_int(0, d, off); return d; @@ -314,21 +314,21 @@ unsigned char *serial_dump_buffer(struct Buffer *b, unsigned char *d, int *off, else d = serial_dump_int(1, d, off); - d = serial_dump_char_size(b->data, d, off, b->dsize + 1, convert); - d = serial_dump_int(b->dptr - b->data, d, off); - d = serial_dump_int(b->dsize, d, off); + d = serial_dump_char_size(buf->data, d, off, buf->dsize + 1, convert); + d = serial_dump_int(buf->dptr - buf->data, d, off); + d = serial_dump_int(buf->dsize, d, off); return d; } /** * serial_restore_buffer - Unpack a Buffer from a binary blob - * @param[out] b Store the unpacked Buffer here + * @param[out] buf Store the unpacked Buffer here * @param[in] d Binary blob to read from * @param[out] off Offset into the blob * @param[in] convert If true, the strings will be converted from utf-8 */ -void serial_restore_buffer(struct Buffer *b, const unsigned char *d, int *off, bool convert) +void serial_restore_buffer(struct Buffer *buf, const unsigned char *d, int *off, bool convert) { unsigned int used; unsigned int offset; @@ -338,11 +338,11 @@ void serial_restore_buffer(struct Buffer *b, const unsigned char *d, int *off, b return; } - serial_restore_char(&b->data, d, off, convert); + serial_restore_char(&buf->data, d, off, convert); serial_restore_int(&offset, d, off); - b->dptr = b->data + offset; + buf->dptr = buf->data + offset; serial_restore_int(&used, d, off); - b->dsize = used; + buf->dsize = used; } /** diff --git a/hcache/serialize.h b/hcache/serialize.h index 495c2e195..b3e96988a 100644 --- a/hcache/serialize.h +++ b/hcache/serialize.h @@ -40,7 +40,7 @@ struct ParameterList; unsigned char *serial_dump_address(struct Address *a, unsigned char *d, int *off, bool convert); unsigned char *serial_dump_body(struct Body *c, unsigned char *d, int *off, bool convert); -unsigned char *serial_dump_buffer(struct Buffer *b, unsigned char *d, int *off, bool convert); +unsigned char *serial_dump_buffer(struct Buffer *buf, unsigned char *d, int *off, bool convert); unsigned char *serial_dump_char(char *c, unsigned char *d, int *off, bool convert); unsigned char *serial_dump_char_size(char *c, unsigned char *d, int *off, ssize_t size, bool convert); unsigned char *serial_dump_envelope(struct Envelope *e, unsigned char *d, int *off, bool convert); @@ -51,7 +51,7 @@ unsigned char *serial_dump_stailq(struct ListHead *l, unsigned char *d, int *off void serial_restore_address(struct Address **a, const unsigned char *d, int *off, bool convert); void serial_restore_body(struct Body *c, const unsigned char *d, int *off, bool convert); -void serial_restore_buffer(struct Buffer *b, const unsigned char *d, int *off, bool convert); +void serial_restore_buffer(struct Buffer *buf, const unsigned char *d, int *off, bool convert); void serial_restore_char(char **c, const unsigned char *d, int *off, bool convert); void serial_restore_envelope(struct Envelope *e, const unsigned char *d, int *off, bool convert); void serial_restore_int(unsigned int *i, const unsigned char *d, int *off); diff --git a/imap/imap.c b/imap/imap.c index ee45364e9..fd94292c3 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -621,13 +621,13 @@ int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char imap_munge_mbox_name(adata->unicode, oldmbox, sizeof(oldmbox), oldname); imap_munge_mbox_name(adata->unicode, newmbox, sizeof(newmbox), newname); - struct Buffer *b = mutt_buffer_pool_get(); - mutt_buffer_printf(b, "RENAME %s %s", oldmbox, newmbox); + struct Buffer *buf = mutt_buffer_pool_get(); + mutt_buffer_printf(buf, "RENAME %s %s", oldmbox, newmbox); - if (imap_exec(adata, mutt_b2s(b), IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS) + if (imap_exec(adata, mutt_b2s(buf), IMAP_CMD_NO_FLAGS) != IMAP_EXEC_SUCCESS) rc = -1; - mutt_buffer_pool_release(&b); + mutt_buffer_pool_release(&buf); return rc; } diff --git a/imap/message.c b/imap/message.c index 2cb5bee01..c1b506594 100644 --- a/imap/message.c +++ b/imap/message.c @@ -583,7 +583,7 @@ static void imap_alloc_uid_hash(struct ImapAccountData *adata, unsigned int msn_ /** * imap_fetch_msn_seqset - Generate a sequence set - * @param[in] b Buffer for the result + * @param[in] buf Buffer for the result * @param[in] adata Imap Account data * @param[in] evalhc If true, check the Header Cache * @param[in] msn_begin First Message Sequence Number @@ -593,7 +593,7 @@ static void imap_alloc_uid_hash(struct ImapAccountData *adata, unsigned int msn_ * Generates a more complicated sequence set after using the header cache, * in case there are missing MSNs in the middle. */ -static unsigned int imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountData *adata, +static unsigned int imap_fetch_msn_seqset(struct Buffer *buf, struct ImapAccountData *adata, bool evalhc, unsigned int msn_begin, unsigned int msn_end, unsigned int *fetch_msn_end) { @@ -606,7 +606,7 @@ static unsigned int imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountDa unsigned int range_end = 0; unsigned int msn_count = 0; - mutt_buffer_reset(b); + mutt_buffer_reset(buf); if (msn_end < msn_begin) return 0; @@ -619,7 +619,7 @@ static unsigned int imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountDa *fetch_msn_end = msn_end; else *fetch_msn_end = msn_begin + max_headers_per_fetch - 1; - mutt_buffer_printf(b, "%u:%u", msn_begin, *fetch_msn_end); + mutt_buffer_printf(buf, "%u:%u", msn_begin, *fetch_msn_end); return (*fetch_msn_end - msn_begin + 1); } @@ -648,15 +648,15 @@ static unsigned int imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountDa if (first_chunk) first_chunk = false; else - mutt_buffer_addch(b, ','); + mutt_buffer_addch(buf, ','); if (state == 1) - mutt_buffer_add_printf(b, "%u", range_begin); + mutt_buffer_add_printf(buf, "%u", range_begin); else if (state == 2) - mutt_buffer_add_printf(b, "%u:%u", range_begin, range_end); + mutt_buffer_add_printf(buf, "%u:%u", range_begin, range_end); state = 0; - if ((mutt_buffer_len(b) > 500) || (msn_count >= max_headers_per_fetch)) + if ((mutt_buffer_len(buf) > 500) || (msn_count >= max_headers_per_fetch)) break; } } @@ -1036,7 +1036,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, char tempfile[_POSIX_PATH_MAX]; FILE *fp = NULL; struct ImapHeader h; - struct Buffer *b = NULL; + struct Buffer *buf = NULL; static const char *const want_headers = "DATE FROM SENDER SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE " "CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL " @@ -1094,7 +1094,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, mutt_progress_init(&progress, _("Fetching message headers..."), MUTT_PROGRESS_MSG, C_ReadInc, msn_end); - b = mutt_buffer_pool_get(); + buf = mutt_buffer_pool_get(); /* NOTE: * The (fetch_msn_end < msn_end) used to be important to prevent @@ -1107,11 +1107,11 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, * cautious I'm keeping it. */ while ((fetch_msn_end < msn_end) && - imap_fetch_msn_seqset(b, adata, evalhc, msn_begin, msn_end, &fetch_msn_end)) + imap_fetch_msn_seqset(buf, adata, evalhc, msn_begin, msn_end, &fetch_msn_end)) { char *cmd = NULL; mutt_str_asprintf(&cmd, "FETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE %s)", - mutt_b2s(b), hdrreq); + mutt_b2s(buf), hdrreq); imap_cmd_start(adata, cmd); FREE(&cmd); @@ -1245,7 +1245,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, bail: mutt_buffer_pool_release(&hdr_list); - mutt_buffer_pool_release(&b); + mutt_buffer_pool_release(&buf); mutt_file_fclose(&fp); FREE(&hdrreq); @@ -1735,10 +1735,8 @@ int imap_copy_messages(struct Mailbox *m, struct EmailList *el, char *dest, bool rc = 0; out: - if (cmd.data) - FREE(&cmd.data); - if (sync_cmd.data) - FREE(&sync_cmd.data); + FREE(&cmd.data); + FREE(&sync_cmd.data); return (rc < 0) ? -1 : rc; } diff --git a/imap/util.c b/imap/util.c index 1e54281c8..611bc704a 100644 --- a/imap/util.c +++ b/imap/util.c @@ -339,13 +339,13 @@ void imap_clean_path(char *path, size_t plen) #ifdef USE_HCACHE /** * imap_msn_index_to_uid_seqset - Convert MSN index of UIDs to Seqset - * @param b Buffer for the result + * @param buf Buffer for the result * @param mdata Imap Mailbox data * * Generates a seqseq of the UIDs in msn_index to persist in the header cache. * Empty spots are stored as 0. */ -static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapMboxData *mdata) +static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata) { int first = 1, state = 0; unsigned int cur_uid = 0, last_uid = 0; @@ -384,12 +384,12 @@ static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapMboxData * if (first) first = 0; else - mutt_buffer_addch(b, ','); + mutt_buffer_addch(buf, ','); if (state == 1) - mutt_buffer_add_printf(b, "%u", range_begin); + mutt_buffer_add_printf(buf, "%u", range_begin); else if (state == 2) - mutt_buffer_add_printf(b, "%u:%u", range_begin, range_end); + mutt_buffer_add_printf(buf, "%u:%u", range_begin, range_end); state = 1; range_begin = cur_uid; @@ -527,13 +527,13 @@ int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata) return -1; /* The seqset is likely large. Preallocate to reduce reallocs */ - struct Buffer b = mutt_buffer_make(8192); - imap_msn_index_to_uid_seqset(&b, mdata); + struct Buffer buf = mutt_buffer_make(8192); + imap_msn_index_to_uid_seqset(&buf, mdata); - int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, b.data, - mutt_buffer_len(&b) + 1); - mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", b.data); - mutt_buffer_dealloc(&b); + int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, buf.data, + mutt_buffer_len(&buf) + 1); + mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", buf.data); + mutt_buffer_dealloc(&buf); return rc; } diff --git a/mutt/pool.c b/mutt/pool.c index 3ca1145fc..1b6fea450 100644 --- a/mutt/pool.c +++ b/mutt/pool.c @@ -45,9 +45,9 @@ static struct Buffer **BufferPool = NULL; */ static struct Buffer *buffer_new(void) { - struct Buffer *b = mutt_mem_malloc(sizeof(struct Buffer)); - mutt_buffer_init(b); - return b; + struct Buffer *buf = mutt_mem_malloc(sizeof(struct Buffer)); + mutt_buffer_init(buf); + return buf; } /** diff --git a/mutt_attach.c b/mutt_attach.c index e449caed1..b7e46f497 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -358,10 +358,8 @@ void mutt_check_lookup_list(struct Body *b, char *type, size_t len) tmp.subtype); mutt_debug(LL_DEBUG1, "\"%s\" -> %s\n", b->filename, type); } - if (tmp.subtype) - FREE(&tmp.subtype); - if (tmp.xtype) - FREE(&tmp.xtype); + FREE(&tmp.subtype); + FREE(&tmp.xtype); } } } diff --git a/pager.c b/pager.c index 0e570f41b..29d09524e 100644 --- a/pager.c +++ b/pager.c @@ -575,8 +575,7 @@ static void cleanup_quote(struct QClass **quote_list) if ((*quote_list)->down) cleanup_quote(&((*quote_list)->down)); ptr = (*quote_list)->next; - if ((*quote_list)->prefix) - FREE(&(*quote_list)->prefix); + FREE(&(*quote_list)->prefix); FREE(quote_list); *quote_list = ptr; } @@ -2720,8 +2719,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P regfree(&rd.search_re); for (size_t i = 0; i < rd.last_line; i++) { - if (rd.line_info[i].search) - FREE(&(rd.line_info[i].search)); + FREE(&(rd.line_info[i].search)); rd.line_info[i].search_cnt = -1; } } @@ -2735,8 +2733,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P for (size_t i = 0; i < rd.max_line; i++) { /* cleanup */ - if (rd.line_info[i].search) - FREE(&(rd.line_info[i].search)); + FREE(&(rd.line_info[i].search)); rd.line_info[i].search_cnt = -1; } rd.search_flag = 0;