From 72a8bb4091a7d8336211ed81582fee101988ef1b Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 14 Apr 2019 09:20:46 -0700 Subject: [PATCH] Convert remaining mutt_adv_mktemp() calls to use buffer version Co-authored-by: Richard Russon --- mutt_body.c | 17 +++++++++-------- postpone.c | 14 ++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/mutt_body.c b/mutt_body.c index fb9943f74..9a7787533 100644 --- a/mutt_body.c +++ b/mutt_body.c @@ -50,25 +50,26 @@ int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src) if (!tgt || !src) return -1; - char tmp[PATH_MAX]; struct Body *b = NULL; - bool use_disp; + struct Buffer *tmp = mutt_buffer_pool_get(); if (src->filename) { use_disp = true; - mutt_str_strfcpy(tmp, src->filename, sizeof(tmp)); + mutt_buffer_strcpy(tmp, src->filename); } else { use_disp = false; - tmp[0] = '\0'; } - mutt_adv_mktemp(tmp, sizeof(tmp)); - if (mutt_save_attachment(fp, src, tmp, MUTT_SAVE_NO_FLAGS, NULL) == -1) + mutt_buffer_adv_mktemp(tmp); + if (mutt_save_attachment(fp, src, mutt_b2s(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1) + { + mutt_buffer_pool_release(&tmp); return -1; + } *tgt = mutt_body_new(); b = *tgt; @@ -78,7 +79,7 @@ int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src) b->parts = NULL; b->next = NULL; - b->filename = mutt_str_strdup(tmp); + b->filename = mutt_str_strdup(mutt_b2s(tmp)); b->use_disp = use_disp; b->unlink = true; @@ -112,6 +113,6 @@ int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src) } mutt_stamp_attachment(b); - + mutt_buffer_pool_release(&tmp); return 0; } diff --git a/postpone.c b/postpone.c index a0007bd98..f5e692028 100644 --- a/postpone.c +++ b/postpone.c @@ -581,7 +581,6 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, struct Email *e, bool resend) { struct Message *msg = NULL; - char file[PATH_MAX]; struct Body *b = NULL; FILE *fp_body = NULL; int rc = -1; @@ -680,16 +679,18 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, s.fp_in = fp_body; + struct Buffer *file = mutt_buffer_pool_get(); + /* create temporary files for all attachments */ for (b = newhdr->content; b; b = b->next) { /* what follows is roughly a receive-mode variant of * mutt_get_tmp_attachment () from muttlib.c */ - file[0] = '\0'; + mutt_buffer_reset(file); if (b->filename) { - mutt_str_strfcpy(file, b->filename, sizeof(file)); + mutt_buffer_strcpy(file, b->filename); b->d_filename = mutt_str_strdup(b->filename); } else @@ -718,8 +719,8 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, mutt_param_delete(&b->parameter, "x-mutt-noconv"); } - mutt_adv_mktemp(file, sizeof(file)); - s.fp_out = mutt_file_fopen(file, "w"); + mutt_buffer_adv_mktemp(file); + s.fp_out = mutt_file_fopen(mutt_b2s(file), "w"); if (!s.fp_out) goto bail; @@ -777,7 +778,7 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, if (mutt_file_fclose(&s.fp_out) != 0) goto bail; - mutt_str_replace(&b->filename, file); + mutt_str_replace(&b->filename, mutt_b2s(file)); b->unlink = true; mutt_stamp_attachment(b); @@ -817,6 +818,7 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, bail: /* that's it. */ + mutt_buffer_pool_release(&file); if (fp_body != fp) mutt_file_fclose(&fp_body); if (msg) -- 2.40.0