Skip to content

Commit

Permalink
merge: minor code fixes
Browse files Browse the repository at this point in the history
 * doxy: cross-link events
 * tidy mutt_edit_headers
 * tidy code
 * tidy old_flags
 * compose: return early
 * fix coverity defects
  • Loading branch information
flatcap committed Feb 15, 2022
2 parents 5ecb56e + 2b21246 commit 87167cb
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 56 deletions.
2 changes: 2 additions & 0 deletions alternates.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct Buffer;
/**
* enum NotifyAlternates - Alternates command notification types
*
* Observers of #NT_ALTERN will not be passed any Event data.
*
* @note Notifications are sent **after** the event.
*/
enum NotifyAlternates
Expand Down
2 changes: 2 additions & 0 deletions attach/attachments.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct Mailbox;
/**
* enum NotifyAttach - Attachments notification types
*
* Observers of #NT_ATTACH will not be passed any Event data.
*
* @note Notifications are sent **after** the event.
*/
enum NotifyAttach
Expand Down
2 changes: 1 addition & 1 deletion attach/recvattach.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void mutt_update_v2r(struct AttachCtx *actx)
*/
void mutt_update_tree(struct AttachCtx *actx)
{
char buf[256];
char buf[256] = { 0 };
char *s = NULL;

mutt_update_v2r(actx);
Expand Down
2 changes: 1 addition & 1 deletion autocrypt/autocrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_
* If the recommendataion is > NO and keylist is not NULL, keylist will be
* populated with the autocrypt keyids.
*/
enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Email *e, char **keylist)
enum AutocryptRec mutt_autocrypt_ui_recommendation(const struct Email *e, char **keylist)
{
enum AutocryptRec rc = AUTOCRYPT_REC_OFF;
struct AutocryptAccount *account = NULL;
Expand Down
2 changes: 1 addition & 1 deletion autocrypt/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int mutt_autocrypt_init (bool can_create);
int mutt_autocrypt_process_autocrypt_header(struct Email *e, struct Envelope *env);
int mutt_autocrypt_process_gossip_header (struct Email *e, struct Envelope *prot_headers);
int mutt_autocrypt_set_sign_as_default_key (struct Email *e);
enum AutocryptRec mutt_autocrypt_ui_recommendation (struct Email *e, char **keylist);
enum AutocryptRec mutt_autocrypt_ui_recommendation (const struct Email *e, char **keylist);
int mutt_autocrypt_write_autocrypt_header (struct Envelope *env, FILE *fp);
int mutt_autocrypt_write_gossip_headers (struct Envelope *env, FILE *fp);

Expand Down
5 changes: 0 additions & 5 deletions compose/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,6 @@ int mutt_compose_menu(struct Email *e, struct Buffer *fcc, uint8_t flags,
shared->news = OptNewsSend;
#endif

#ifdef USE_NNTP
if (shared->news)
dlg->help_data = ComposeNewsHelp;
#endif

notify_observer_add(NeoMutt->notify, NT_CONFIG, compose_config_observer, dlg);
notify_observer_add(dlg->notify, NT_WINDOW, compose_window_observer, dlg);
dialog_push(dlg);
Expand Down
54 changes: 31 additions & 23 deletions compose/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1793,19 +1793,24 @@ static int op_envelope_edit_fcc(struct ComposeSharedData *shared, int op)
int rc = IR_NO_ACTION;
struct Buffer *fname = mutt_buffer_pool_get();
mutt_buffer_copy(fname, shared->fcc);

if (mutt_buffer_get_field(Prompts[HDR_FCC], fname, MUTT_COMP_FILE | MUTT_COMP_CLEAR,
false, NULL, NULL, NULL) == 0)
false, NULL, NULL, NULL) != 0)
{
if (!mutt_str_equal(shared->fcc->data, fname->data))
{
mutt_buffer_copy(shared->fcc, fname);
mutt_buffer_pretty_mailbox(shared->fcc);
shared->fcc_set = true;
notify_send(shared->notify, NT_COMPOSE, NT_COMPOSE_ENVELOPE, NULL);
mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
rc = IR_SUCCESS;
}
goto done; // aborted
}

if (mutt_str_equal(shared->fcc->data, fname->data))
goto done; // no change

mutt_buffer_copy(shared->fcc, fname);
mutt_buffer_pretty_mailbox(shared->fcc);
shared->fcc_set = true;
notify_send(shared->notify, NT_COMPOSE, NT_COMPOSE_ENVELOPE, NULL);
mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
rc = IR_SUCCESS;

done:
mutt_buffer_pool_release(&fname);
return rc;
}
Expand Down Expand Up @@ -1894,17 +1899,20 @@ static int op_envelope_edit_subject(struct ComposeSharedData *shared, int op)

mutt_buffer_strcpy(buf, shared->email->env->subject);
if (mutt_buffer_get_field(Prompts[HDR_SUBJECT], buf, MUTT_COMP_NO_FLAGS,
false, NULL, NULL, NULL) == 0)
false, NULL, NULL, NULL) != 0)
{
if (!mutt_str_equal(shared->email->env->subject, mutt_buffer_string(buf)))
{
mutt_str_replace(&shared->email->env->subject, mutt_buffer_string(buf));
notify_send(shared->notify, NT_COMPOSE, NT_COMPOSE_ENVELOPE, NULL);
mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
rc = IR_SUCCESS;
}
goto done; // aborted
}

if (mutt_str_equal(shared->email->env->subject, mutt_buffer_string(buf)))
goto done; // no change

mutt_str_replace(&shared->email->env->subject, mutt_buffer_string(buf));
notify_send(shared->notify, NT_COMPOSE, NT_COMPOSE_ENVELOPE, NULL);
mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
rc = IR_SUCCESS;

done:
mutt_buffer_pool_release(&buf);
return rc;
}
Expand Down Expand Up @@ -2025,7 +2033,7 @@ static int op_compose_pgp_menu(struct ComposeSharedData *shared, int op)
}
shared->email->security = crypt_pgp_send_menu(shared->email);
update_crypt_info(shared);
if (old_flags == shared->email->security)
if (shared->email->security == old_flags)
return IR_NO_ACTION;

mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
Expand Down Expand Up @@ -2160,7 +2168,7 @@ static int op_compose_smime_menu(struct ComposeSharedData *shared, int op)
}
shared->email->security = crypt_smime_send_menu(shared->email);
update_crypt_info(shared);
if (old_flags == shared->email->security)
if (shared->email->security == old_flags)
return IR_NO_ACTION;

mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
Expand Down Expand Up @@ -2207,8 +2215,8 @@ static int op_compose_write_message(struct ComposeSharedData *shared, int op)
* op_display_headers - Display message and toggle header weeding - Implements ::compose_function_t - @ingroup compose_function_api
*
* This function handles:
* - OP_ATTACHMENT_VIEW
* - OP_DISPLAY_HEADERS
* - OP_ATTACHMENT_VIEW
* - OP_DISPLAY_HEADERS
*/
static int op_display_headers(struct ComposeSharedData *shared, int op)
{
Expand Down Expand Up @@ -2294,7 +2302,7 @@ static int op_compose_autocrypt_menu(struct ComposeSharedData *shared, int op)
}
autocrypt_compose_menu(shared->email, shared->sub);
update_crypt_info(shared);
if (old_flags == shared->email->security)
if (shared->email->security == old_flags)
return IR_NO_ACTION;

mutt_message_hook(NULL, shared->email, MUTT_SEND2_HOOK);
Expand Down
1 change: 1 addition & 0 deletions compose/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern int HeaderPadding[];
extern int MaxHeaderWidth;
extern const char *const Prompts[];

// Observers of #NT_COMPOSE will not be passed any Event data.
typedef uint8_t NotifyCompose; ///< Flags, e.g. #NT_COMPOSE_ATTACH
#define NT_COMPOSE_NO_FLAGS 0 ///< No flags are set
#define NT_COMPOSE_ATTACH (1 << 0) ///< Attachments have changed
Expand Down
2 changes: 2 additions & 0 deletions core/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ enum CommandResult
/**
* @defgroup command_api Command API
*
* Observers of #NT_COMMAND will be passed a #Command.
*
* A user-callable command
*/
struct Command
Expand Down
2 changes: 2 additions & 0 deletions core/neomutt.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ extern struct NeoMutt *NeoMutt;

/**
* enum NotifyGlobal - Events not associated with an object
*
* Observers of #NT_GLOBAL will not be passed any Event data.
*/
enum NotifyGlobal
{
Expand Down
10 changes: 5 additions & 5 deletions email/email.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ STAILQ_HEAD(EmailList, EmailNode);
*/
enum NotifyEmail
{
NT_EMAIL_ADD = 1, ///< Email has been added
NT_EMAIL_DELETE, ///< Email is about to be deleted
NT_EMAIL_DELETE_ALL, ///< All the Emails are about to be deleted
NT_EMAIL_CHANGE, ///< Email has changed
NT_EMAIL_ADD = 1, ///< Email has been added
NT_EMAIL_DELETE, ///< Email is about to be deleted
NT_EMAIL_DELETE_ALL, ///< All the Emails are about to be deleted
NT_EMAIL_CHANGE, ///< Email has changed
};

/**
Expand All @@ -162,7 +162,7 @@ struct EventEmail
/**
* enum NotifyHeader - Types of Header Event
*
* Observers on #NT_HEADER will be passed an #EventHeader
* Observers of #NT_HEADER will be passed an #EventHeader.
*/
enum NotifyHeader
{
Expand Down
1 change: 1 addition & 0 deletions index/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct Email;
struct Menu;
struct MuttWindow;

// Observers of #NT_INDEX will be passed an #IndexSharedData.
typedef uint8_t NotifyIndex; ///< Flags, e.g. #NT_INDEX_ACCOUNT
#define NT_INDEX_NO_FLAGS 0 ///< No flags are set
#define NT_INDEX_ADD (1 << 0) ///< New Index Shared Data has been created
Expand Down
2 changes: 1 addition & 1 deletion init.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static char *getmailname(void)
static bool get_hostname(struct ConfigSet *cs)
{
const char *short_host = NULL;
struct utsname utsname;
struct utsname utsname = { 0 };

const char *const c_hostname = cs_subset_string(NeoMutt->sub, "hostname");
if (c_hostname)
Expand Down
1 change: 1 addition & 0 deletions menu/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

struct ConfigSubset;

// Observers of #NT_MENU will not be passed any Event data.
typedef uint8_t MenuRedrawFlags; ///< Flags, e.g. #MENU_REDRAW_INDEX
#define MENU_REDRAW_NO_FLAGS 0 ///< No flags are set
#define MENU_REDRAW_INDEX (1 << 0) ///< Redraw the index
Expand Down
35 changes: 16 additions & 19 deletions mutt_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ int mutt_label_message(struct Mailbox *m, struct EmailList *el)
void mutt_edit_headers(const char *editor, const char *body, struct Email *e,
struct Buffer *fcc)
{
char buf[1024];
const char *p = NULL;
int i;
struct Envelope *n = NULL;
time_t mtime;
struct stat st = { 0 };

struct Buffer *path = mutt_buffer_pool_get();
mutt_buffer_mktemp(path);
FILE *fp_out = mutt_file_fopen(mutt_buffer_string(path), "w");
Expand Down Expand Up @@ -207,13 +200,14 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *e,
mutt_file_fclose(&fp_in);
mutt_file_fclose(&fp_out);

struct stat st = { 0 };
if (stat(mutt_buffer_string(path), &st) == -1)
{
mutt_perror(mutt_buffer_string(path));
goto cleanup;
}

mtime = mutt_file_decrease_mtime(mutt_buffer_string(path), &st);
time_t mtime = mutt_file_decrease_mtime(mutt_buffer_string(path), &st);
if (mtime == (time_t) -1)
{
mutt_perror(mutt_buffer_string(path));
Expand Down Expand Up @@ -249,9 +243,12 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *e,
goto cleanup;
}

n = mutt_rfc822_read_header(fp_in, NULL, true, false);
while ((i = fread(buf, 1, sizeof(buf), fp_in)) > 0)
fwrite(buf, 1, i, fp_out);
struct Envelope *env_new = NULL;
char buf[1024];
env_new = mutt_rfc822_read_header(fp_in, NULL, true, false);
int bytes_read;
while ((bytes_read = fread(buf, 1, sizeof(buf), fp_in)) > 0)
fwrite(buf, 1, bytes_read, fp_out);
mutt_file_fclose(&fp_out);
mutt_file_fclose(&fp_in);
mutt_file_unlink(mutt_buffer_string(path));
Expand All @@ -265,21 +262,21 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *e,
#endif
{
if (!STAILQ_EMPTY(&e->env->in_reply_to) &&
(STAILQ_EMPTY(&n->in_reply_to) ||
!mutt_str_equal(STAILQ_FIRST(&n->in_reply_to)->data,
(STAILQ_EMPTY(&env_new->in_reply_to) ||
!mutt_str_equal(STAILQ_FIRST(&env_new->in_reply_to)->data,
STAILQ_FIRST(&e->env->in_reply_to)->data)))
{
mutt_list_free(&e->env->references);
}
}

/* restore old info. */
mutt_list_free(&n->references);
STAILQ_SWAP(&n->references, &e->env->references, ListNode);
mutt_list_free(&env_new->references);
STAILQ_SWAP(&env_new->references, &e->env->references, ListNode);

mutt_env_free(&e->env);
e->env = n;
n = NULL;
e->env = env_new;
env_new = NULL;

mutt_expand_aliases_env(e->env);

Expand All @@ -294,7 +291,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *e,

if (fcc && (plen = mutt_istr_startswith(np->data, "fcc:")))
{
p = mutt_str_skip_email_wsp(np->data + plen);
const char *p = mutt_str_skip_email_wsp(np->data + plen);
if (*p)
{
mutt_buffer_strcpy(fcc, p);
Expand All @@ -307,7 +304,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Email *e,
struct Body *body2 = NULL;
struct Body *parts = NULL;

p = mutt_str_skip_email_wsp(np->data + plen);
const char *p = mutt_str_skip_email_wsp(np->data + plen);
if (*p)
{
mutt_buffer_reset(path);
Expand Down
2 changes: 2 additions & 0 deletions ncrypt/gnupgparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, bool *is_subkey, struct PgpK
/* merge temp key back into real key */
if (!(is_uid || is_fpr || (*is_subkey && c_pgp_ignore_subkeys)))
k = mutt_mem_malloc(sizeof(*k));
if (!k)
return NULL;
memcpy(k, &tmp, sizeof(*k));
/* fixup parentship of uids after merging the temp key into
* the real key */
Expand Down
1 change: 1 addition & 0 deletions pager/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ struct PagerView
struct MuttWindow *win_pager; ///< Pager Window
};

// Observers of #NT_PAGER will be passed a #PagerPrivateData.
typedef uint8_t NotifyPager; ///< Flags, e.g. #NT_PAGER_DELETE
#define NT_PAGER_NO_FLAGS 0 ///< No flags are set
#define NT_PAGER_DELETE (1 << 0) ///< Pager Private Data is about to be freed
Expand Down
2 changes: 2 additions & 0 deletions subjectrx.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct Envelope;
/**
* enum NotifySubjRx - Subject Regex notification types
*
* Observers of #NT_SUBJRX will not be passed any Event data.
*
* @note Notifications are sent **after** the event.
*/
enum NotifySubjRx
Expand Down

0 comments on commit 87167cb

Please sign in to comment.