From f94b7c13ac5fcf89dc9c96b99df275250c9c7721 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 1 Oct 2019 11:33:09 +0100 Subject: [PATCH] buffer: tidy checks for empty Buffers --- browser.c | 20 +++++++++++--------- mutt_attach.c | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/browser.c b/browser.c index 617b5a1e6..382710c00 100644 --- a/browser.c +++ b/browser.c @@ -1173,9 +1173,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, #ifdef USE_NNTP if (OptNews) { - if (mutt_b2s(file)[0] != '\0') - mutt_buffer_strcpy(prefix, mutt_b2s(file)); - else + if (mutt_buffer_is_empty(file)) { struct NntpAccountData *adata = CurrentNewsSrv; @@ -1191,10 +1189,14 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, } } } + else + { + mutt_buffer_strcpy(prefix, mutt_b2s(file)); + } } else #endif - if (mutt_b2s(file)[0] != '\0') + if (!mutt_buffer_is_empty(file)) { mutt_buffer_expand_path(file); #ifdef USE_IMAP @@ -1276,7 +1278,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, * meaning only with sort methods SUBJECT/DESC for now. */ if (CurrentFolder) { - if (mutt_b2s(&LastDir)[0] == '\0') + if (mutt_buffer_is_empty(&LastDir)) { /* If browsing in "local"-mode, than we chose to define LastDir to * MailDir */ @@ -1323,7 +1325,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, while ((i > 0) && (mutt_b2s(&LastDir)[--i] == '/')) LastDir.data[i] = '\0'; mutt_buffer_fix_dptr(&LastDir); - if (mutt_b2s(&LastDir)[0] == '\0') + if (mutt_buffer_is_empty(&LastDir)) mutt_path_getcwd(&LastDir); } } @@ -1548,7 +1550,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, } *files = tfiles; } - else if (mutt_b2s(file)[0] != '\0') /* no tagged entries. return selected entry */ + else if (!mutt_buffer_is_empty(file)) /* no tagged entries. return selected entry */ { *numfiles = 1; tfiles = mutt_mem_calloc(*numfiles, sizeof(char *)); @@ -1693,7 +1695,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, else if (op == OP_GOTO_PARENT) mutt_get_parent_path(mutt_b2s(buf), buf->data, buf->dsize); - if (mutt_b2s(buf)[0] != '\0') + if (!mutt_buffer_is_empty(buf)) { mailbox = false; mutt_buffer_expand_path(buf); @@ -1765,7 +1767,7 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, mailbox = false; /* assume that the user wants to see everything */ - if (mutt_b2s(buf)[0] == '\0') + if (mutt_buffer_is_empty(buf)) mutt_buffer_strcpy(buf, "."); struct Buffer errmsg = { 0 }; diff --git a/mutt_attach.c b/mutt_attach.c index e8098f316..0083a01aa 100644 --- a/mutt_attach.c +++ b/mutt_attach.c @@ -637,7 +637,7 @@ return_error: if (!entry || !entry->xneomuttkeep) { - if (fp && mutt_b2s(tmpfile)[0]) + if (fp && !mutt_buffer_is_empty(tmpfile)) { /* add temporary file to TempAttachmentsList to be deleted on timeout hook */ mutt_add_temp_attachment(mutt_b2s(tmpfile)); @@ -650,7 +650,7 @@ return_error: mailcap_entry_free(&entry); - if (mutt_b2s(pagerfile)[0] != '\0') + if (!mutt_buffer_is_empty(pagerfile)) mutt_file_unlink(mutt_b2s(pagerfile)); mutt_buffer_pool_release(&tmpfile); -- 2.40.0