Skip to content

Commit

Permalink
initialise struct stat
Browse files Browse the repository at this point in the history
  • Loading branch information
flatcap committed Oct 15, 2021
1 parent 23c300f commit 2a3aaec
Show file tree
Hide file tree
Showing 36 changed files with 87 additions and 82 deletions.
4 changes: 2 additions & 2 deletions attach/mutt_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
int mutt_get_tmp_attachment(struct Body *a)
{
char type[256];
struct stat st;
struct stat st = { 0 };

if (a->unlink)
return 0;
Expand Down Expand Up @@ -1039,7 +1039,7 @@ int mutt_decode_save_attachment(FILE *fp, struct Body *m, const char *path,
{
/* When called from the compose menu, the attachment isn't parsed,
* so we need to do it here. */
struct stat st;
struct stat st = { 0 };

if (stat(m->filename, &st) == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion attach/recvattach.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static int query_save_attachment(FILE *fp, struct Body *body, struct Email *e, c

if (is_message)
{
struct stat st;
struct stat st = { 0 };

/* check to make sure that this file is really the one the user wants */
rc = mutt_save_confirm(mutt_buffer_string(buf), &st);
Expand Down
2 changes: 1 addition & 1 deletion autocrypt/autocrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
static int autocrypt_dir_init(bool can_create)
{
int rc = 0;
struct stat st;
struct stat st = { 0 };

const char *const c_autocrypt_dir =
cs_subset_path(NeoMutt->sub, "autocrypt_dir");
Expand Down
2 changes: 1 addition & 1 deletion autocrypt/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int mutt_autocrypt_db_init(bool can_create)
struct Buffer *db_path = mutt_buffer_pool_get();
mutt_buffer_concat_path(db_path, c_autocrypt_dir, "autocrypt.db");

struct stat st;
struct stat st = { 0 };
if (stat(mutt_buffer_string(db_path), &st) == 0)
{
if (sqlite3_open_v2(mutt_buffer_string(db_path), &AutocryptDB,
Expand Down
6 changes: 3 additions & 3 deletions bcache/bcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int bcache_path(struct ConnAccount *account, const char *mailbox, struct
if (!account || !c_message_cachedir || !bcache)
return -1;

struct stat st;
struct stat st = { 0 };
if (!((stat(c_message_cachedir, &st) == 0) && S_ISDIR(st.st_mode)))
{
mutt_error(_("Cache disabled, $message_cachedir isn't a directory: %s"), c_message_cachedir);
Expand Down Expand Up @@ -212,7 +212,7 @@ FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id)
struct Buffer *path = mutt_buffer_pool_get();
mutt_buffer_printf(path, "%s%s%s", bcache->path, id, ".tmp");

struct stat st;
struct stat st = { 0 };
if (stat(bcache->path, &st) == 0)
{
if (!S_ISDIR(st.st_mode))
Expand Down Expand Up @@ -294,7 +294,7 @@ int mutt_bcache_exists(struct BodyCache *bcache, const char *id)
mutt_buffer_addstr(path, id);

int rc = 0;
struct stat st;
struct stat st = { 0 };
if (stat(mutt_buffer_string(path), &st) < 0)
rc = -1;
else
Expand Down
10 changes: 5 additions & 5 deletions browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static void browser_sort(struct BrowserState *state)
*/
static bool link_is_dir(const char *folder, const char *path)
{
struct stat st;
struct stat st = { 0 };
bool retval = false;

struct Buffer *fullpath = mutt_buffer_pool_get();
Expand Down Expand Up @@ -761,7 +761,7 @@ static int examine_directory(struct Mailbox *m, struct Menu *menu,
else
#endif /* USE_NNTP */
{
struct stat st;
struct stat st = { 0 };
DIR *dp = NULL;
struct dirent *de = NULL;

Expand Down Expand Up @@ -861,7 +861,7 @@ static int examine_directory(struct Mailbox *m, struct Menu *menu,
*/
static int examine_mailboxes(struct Mailbox *m, struct Menu *menu, struct BrowserState *state)
{
struct stat st;
struct stat st = { 0 };
struct Buffer *md = NULL;
struct Buffer *mailbox = NULL;

Expand Down Expand Up @@ -940,7 +940,7 @@ static int examine_mailboxes(struct Mailbox *m, struct Menu *menu, struct Browse

if (np->mailbox->type == MUTT_MAILDIR)
{
struct stat st2;
struct stat st2 = { 0 };

mutt_buffer_printf(md, "%s/new", mailbox_path(np->mailbox));
if (stat(mutt_buffer_string(md), &st) < 0)
Expand Down Expand Up @@ -1862,7 +1862,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags,
if (mutt_path_realpath(buf->data) == 0)
break;

struct stat st;
struct stat st = { 0 };
if (stat(mutt_buffer_string(buf), &st) == 0)
{
if (S_ISDIR(st.st_mode))
Expand Down
2 changes: 1 addition & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ int mutt_save_message(struct Mailbox *m, struct EmailList *el,
struct Mailbox *m_save = NULL;

struct Buffer *buf = mutt_buffer_pool_get();
struct stat st;
struct stat st = { 0 };
struct EmailNode *en = NULL;

STAILQ_FOREACH(en, el, entries)
Expand Down
2 changes: 1 addition & 1 deletion complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int mutt_complete(char *buf, size_t buflen)
}
else
{
struct stat st;
struct stat st = { 0 };

mutt_buffer_strcpy(filepart, de->d_name);

Expand Down
4 changes: 2 additions & 2 deletions compose/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void update_crypt_info(struct ComposeSharedData *shared)
static int check_attachments(struct AttachCtx *actx, struct ConfigSubset *sub)
{
int rc = -1;
struct stat st;
struct stat st = { 0 };
struct Buffer *pretty = NULL, *msg = NULL;

for (int i = 0; i < actx->idxlen; i++)
Expand Down Expand Up @@ -1404,7 +1404,7 @@ static int op_compose_rename_file(struct ComposeSharedData *shared, int op)
if ((mutt_buffer_get_field(_("Rename to: "), fname, MUTT_FILE, false, NULL, NULL, NULL) == 0) &&
!mutt_buffer_is_empty(fname))
{
struct stat st;
struct stat st = { 0 };
if (stat(cur_att->body->filename, &st) == -1)
{
/* L10N: "stat" is a system call. Do "man 2 stat" for more information. */
Expand Down
2 changes: 1 addition & 1 deletion conn/gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int tls_compare_certificates(const gnutls_datum_t *peercert)
unsigned char *ptr = NULL;
gnutls_datum_t b64_data = { 0 };
unsigned char *b64_data_data = NULL;
struct stat st;
struct stat st = { 0 };

const char *const c_certificate_file =
cs_subset_path(NeoMutt->sub, "certificate_file");
Expand Down
2 changes: 1 addition & 1 deletion conn/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static int add_entropy(const char *file)
if (!file)
return 0;

struct stat st;
struct stat st = { 0 };
int n = -1;

if (stat(file, &st) == -1)
Expand Down
6 changes: 3 additions & 3 deletions core/mailbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ struct Mailbox *mailbox_find(const char *path)
if (!path)
return NULL;

struct stat st;
struct stat st_tmp;
struct stat st = { 0 };
struct stat st_tmp = { 0 };

if (stat(path, &st) != 0)
return NULL;
Expand Down Expand Up @@ -192,7 +192,7 @@ struct Mailbox *mailbox_find_name(const char *name)
*/
void mailbox_update(struct Mailbox *m)
{
struct stat st;
struct stat st = { 0 };

if (!m)
return;
Expand Down
2 changes: 1 addition & 1 deletion editmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int ev_message(enum EvMessage action, struct Mailbox *m, struct Email *e)
char buf[256];
int rc;
FILE *fp = NULL;
struct stat st;
struct stat st = { 0 };
bool old_append = m->append;

struct Buffer *fname = mutt_buffer_pool_get();
Expand Down
2 changes: 1 addition & 1 deletion hcache/hcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static bool create_hcache_dir(const char *path)
static void hcache_per_folder(struct Buffer *hcpath, const char *path,
const char *folder, hcache_namer_t namer)
{
struct stat st;
struct stat st = { 0 };

int plen = mutt_str_len(path);
int rc = stat(path, &st);
Expand Down
10 changes: 5 additions & 5 deletions maildir/maildir.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void maildir_check_dir(struct Mailbox *m, const char *dir_name,
DIR *dirp = NULL;
struct dirent *de = NULL;
char *p = NULL;
struct stat st;
struct stat st = { 0 };

struct Buffer *path = mutt_buffer_pool_get();
struct Buffer *msgpath = mutt_buffer_pool_get();
Expand Down Expand Up @@ -478,7 +478,7 @@ int maildir_sync_message(struct Mailbox *m, int msgno)
void maildir_update_mtime(struct Mailbox *m)
{
char buf[PATH_MAX];
struct stat st;
struct stat st = { 0 };
struct MaildirMboxData *mdata = maildir_mdata_get(m);

snprintf(buf, sizeof(buf), "%s/%s", mailbox_path(m), "cur");
Expand Down Expand Up @@ -1170,8 +1170,8 @@ static bool maildir_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
*/
enum MxStatus maildir_mbox_check(struct Mailbox *m)
{
struct stat st_new; /* status of the "new" subdirectory */
struct stat st_cur; /* status of the "cur" subdirectory */
struct stat st_new = { 0 }; /* status of the "new" subdirectory */
struct stat st_cur = { 0 }; /* status of the "cur" subdirectory */
int changed = MMC_NO_DIRS; /* which subdirectories have changed */
bool occult = false; /* messages were removed from the mailbox */
int num_new = 0; /* number of new messages added to the mailbox */
Expand Down Expand Up @@ -1639,7 +1639,7 @@ static enum MailboxType maildir_path_probe(const char *path, const struct stat *
char cur[PATH_MAX];
snprintf(cur, sizeof(cur), "%s/cur", path);

struct stat st_cur;
struct stat st_cur = { 0 };
if ((stat(cur, &st_cur) == 0) && S_ISDIR(st_cur.st_mode))
return MUTT_MAILDIR;

Expand Down
7 changes: 4 additions & 3 deletions maildir/mh.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
static int mh_already_notified(struct Mailbox *m, int msgno)
{
char path[PATH_MAX];
struct stat st;
struct stat st = { 0 };

if ((snprintf(path, sizeof(path), "%s/%d", mailbox_path(m), msgno) < sizeof(path)) &&
(stat(path, &st) == 0))
Expand Down Expand Up @@ -477,7 +477,7 @@ int mh_sync_message(struct Mailbox *m, int msgno)
void mh_update_mtime(struct Mailbox *m)
{
char buf[PATH_MAX];
struct stat st;
struct stat st = { 0 };
struct MaildirMboxData *mdata = maildir_mdata_get(m);

snprintf(buf, sizeof(buf), "%s/.mh_sequences", mailbox_path(m));
Expand Down Expand Up @@ -895,7 +895,8 @@ static bool mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
enum MxStatus mh_mbox_check(struct Mailbox *m)
{
char buf[PATH_MAX];
struct stat st, st_cur;
struct stat st = { 0 };
struct stat st_cur = { 0 };
bool modified = false, occult = false, flags_changed = false;
int num_new = 0;
struct MhSequences mhs = { 0 };
Expand Down
2 changes: 1 addition & 1 deletion maildir/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ int mh_seq_read(struct MhSequences *mhs, const char *path)
int mh_seq_changed(struct Mailbox *m)
{
char path[PATH_MAX];
struct stat st;
struct stat st = { 0 };

if ((snprintf(path, sizeof(path), "%s/.mh_sequences", mailbox_path(m)) < sizeof(path)) &&
(stat(path, &st) == 0))
Expand Down
2 changes: 1 addition & 1 deletion maildir/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mode_t mh_umask(struct Mailbox *m)
if (mdata && mdata->mh_umask)
return mdata->mh_umask;

struct stat st;
struct stat st = { 0 };
if (stat(mailbox_path(m), &st) != 0)
{
mutt_debug(LL_DEBUG1, "stat failed on %s\n", mailbox_path(m));
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ int main(int argc, char *argv[], char *envp[])
const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
if (!OptNoCurses && c_folder)
{
struct stat st;
struct stat st = { 0 };
struct Buffer *fpath = mutt_buffer_pool_get();

mutt_buffer_strcpy(fpath, c_folder);
Expand Down Expand Up @@ -1069,7 +1069,7 @@ int main(int argc, char *argv[], char *envp[])
if (draft_file)
{
struct Envelope *opts_env = e->env;
struct stat st;
struct stat st = { 0 };

sendflags |= SEND_DRAFT_FILE;

Expand Down
10 changes: 5 additions & 5 deletions mbox/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static enum MxOpenReturns mmdf_parse_mailbox(struct Mailbox *m)
time_t t;
LOFF_T loc, tmploc;
struct Email *e = NULL;
struct stat st;
struct stat st = { 0 };
struct Progress *progress = NULL;
enum MxOpenReturns rc = MX_OPEN_ERROR;

Expand Down Expand Up @@ -355,7 +355,7 @@ static enum MxOpenReturns mbox_parse_mailbox(struct Mailbox *m)
if (!adata)
return MX_OPEN_ERROR;

struct stat st;
struct stat st = { 0 };
char buf[8192], return_path[256];
struct Email *e_cur = NULL;
time_t t;
Expand Down Expand Up @@ -842,7 +842,7 @@ bool mbox_test_new_folder(const char *path)
void mbox_reset_atime(struct Mailbox *m, struct stat *st)
{
struct utimbuf utimebuf;
struct stat st2;
struct stat st2 = { 0 };

if (!st)
{
Expand Down Expand Up @@ -1035,7 +1035,7 @@ static enum MxStatus mbox_mbox_check(struct Mailbox *m)
if (!adata->fp)
return MX_STATUS_ERROR;

struct stat st;
struct stat st = { 0 };
bool unlock = false;
bool modified = false;

Expand Down Expand Up @@ -1158,7 +1158,7 @@ static enum MxStatus mbox_mbox_sync(struct Mailbox *m)
int need_sort = 0; /* flag to resort mailbox if new mail arrives */
int first = -1; /* first message to be written */
LOFF_T offset; /* location in mailbox to write changed messages */
struct stat st;
struct stat st = { 0 };
struct MUpdate *new_offset = NULL;
struct MUpdate *old_offset = NULL;
FILE *fp = NULL;
Expand Down
4 changes: 2 additions & 2 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static int monitor_handle_ignore(int desc)
{
int new_desc = -1;
struct Monitor *iter = Monitor;
struct stat st;
struct stat st = { 0 };

while (iter && (iter->desc != desc))
iter = iter->next;
Expand Down Expand Up @@ -331,7 +331,7 @@ static int monitor_handle_ignore(int desc)
static enum ResolveResult monitor_resolve(struct MonitorInfo *info, struct Mailbox *m)
{
char *fmt = NULL;
struct stat st;
struct stat st = { 0 };

if (m)
{
Expand Down
Loading

0 comments on commit 2a3aaec

Please sign in to comment.