From 8051bd6f085a490c8af88cc2bf0efcb857c71399 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 26 Sep 2017 17:51:01 +0100 Subject: [PATCH] drop unused param in mutt_bcache_put The 'tmp' param was always true. Factor it out. Thanks to @gahr for the idea/patch. --- bcache.c | 9 +++++++-- bcache.h | 7 ++++--- imap/message.c | 2 +- nntp.c | 2 +- pop.c | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bcache.c b/bcache.c index 509d688cf..3624aa45e 100644 --- a/bcache.c +++ b/bcache.c @@ -150,7 +150,7 @@ FILE *mutt_bcache_get(struct BodyCache *bcache, const char *id) return fp; } -FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id, bool tmp) +FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id) { char path[LONG_STRING]; struct stat sb; @@ -158,6 +158,12 @@ FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id, bool tmp) if (!id || !*id || !bcache) return NULL; + if (snprintf(path, sizeof(path), "%s%s%s", bcache->path, id, ".tmp") >= sizeof(path)) + { + mutt_error(_("Path too long: %s%s%s"), bcache->path, id, ".tmp"); + return NULL; + } + if (stat(bcache->path, &sb) == 0) { if (!S_ISDIR(sb.st_mode)) @@ -175,7 +181,6 @@ FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id, bool tmp) } } - snprintf(path, sizeof(path), "%s%s%s", bcache->path, id, tmp ? ".tmp" : ""); mutt_debug(3, "bcache: put: '%s'\n", path); return safe_fopen(path, "w+"); diff --git a/bcache.h b/bcache.h index 3ee9003d4..9913d5a66 100644 --- a/bcache.h +++ b/bcache.h @@ -63,12 +63,13 @@ FILE *mutt_bcache_get(struct BodyCache *bcache, const char *id); * mutt_bcache_put - Create a file in the Body Cache * @param bcache Body Cache from mutt_bcache_open() * @param id Per-mailbox unique identifier for the message - * @param tmp Returned FILE* is in a temporary location - * If set, use mutt_bcache_commit to put it into place * @retval FILE* on success * @retval NULL on failure + * + * The returned FILE* is in a temporary location. + * Use mutt_bcache_commit to put it into place */ -FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id, bool tmp); +FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id); /** * mutt_bcache_commit - Move a temporary file into the Body Cache diff --git a/imap/message.c b/imap/message.c index e04aae051..ee1be60d8 100644 --- a/imap/message.c +++ b/imap/message.c @@ -109,7 +109,7 @@ static FILE *msg_cache_put(struct ImapData *idata, struct Header *h) idata->bcache = msg_cache_open(idata); snprintf(id, sizeof(id), "%u-%u", idata->uid_validity, HEADER_DATA(h)->uid); - return mutt_bcache_put(idata->bcache, id, true); + return mutt_bcache_put(idata->bcache, id); } static int msg_cache_commit(struct ImapData *idata, struct Header *h) diff --git a/nntp.c b/nntp.c index 07ba52629..f0b72f040 100644 --- a/nntp.c +++ b/nntp.c @@ -1618,7 +1618,7 @@ static int nntp_open_message(struct Context *ctx, struct Message *msg, int msgno /* create new cache file */ mutt_message(fetch_msg); - msg->fp = mutt_bcache_put(nntp_data->bcache, article, true); + msg->fp = mutt_bcache_put(nntp_data->bcache, article); if (!msg->fp) { mutt_mktemp(buf, sizeof(buf)); diff --git a/pop.c b/pop.c index 405ae0d2b..2847b0e5e 100644 --- a/pop.c +++ b/pop.c @@ -599,7 +599,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno NetInc, h->content->length + h->content->offset - 1); /* see if we can put in body cache; use our cache as fallback */ - if (!(msg->fp = mutt_bcache_put(pop_data->bcache, h->data, true))) + if (!(msg->fp = mutt_bcache_put(pop_data->bcache, h->data))) { /* no */ bcache = 0; -- 2.40.0