From 1b67467e661fd6640e2fca57743e9c98ec985f6f Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sun, 19 Aug 2018 02:46:07 +0100 Subject: [PATCH] unify buf,buflen, with reordering --- alias.c | 2 +- conn/sasl_plain.c | 2 +- email/rfc2047.c | 4 ++-- imap/auth_cram.c | 4 ++-- imap/auth_gss.c | 10 ++++----- imap/imap.h | 2 +- imap/imap_private.h | 2 +- imap/util.c | 40 ++++++++++++++++++------------------ mailbox.c | 4 ++-- maildir/mh.c | 24 +++++++++++----------- mutt/base64.c | 46 +++++++++++++++++++++--------------------- mutt/base64.h | 4 ++-- mutt/file.c | 36 ++++++++++++++++----------------- mutt/file.h | 2 +- muttlib.c | 2 +- ncrypt/pgpinvoke.c | 6 +++--- ncrypt/smime.c | 2 +- notmuch/mutt_notmuch.c | 46 +++++++++++++++++++++--------------------- notmuch/mutt_notmuch.h | 2 +- remailer.c | 2 +- rfc1524.c | 6 +++--- sendlib.c | 2 +- test/base64.c | 12 +++++------ 23 files changed, 131 insertions(+), 131 deletions(-) diff --git a/alias.c b/alias.c index 1ab40fb1d..3438d6a52 100644 --- a/alias.c +++ b/alias.c @@ -489,7 +489,7 @@ retry_name: } if (check_alias_name(new->name, NULL, 0)) - mutt_file_quote_filename(buf, sizeof(buf), new->name); + mutt_file_quote_filename(new->name, buf, sizeof(buf)); else mutt_str_strfcpy(buf, new->name, sizeof(buf)); recode_buf(buf, sizeof(buf)); diff --git a/conn/sasl_plain.c b/conn/sasl_plain.c index acbfa7325..90b9b671e 100644 --- a/conn/sasl_plain.c +++ b/conn/sasl_plain.c @@ -67,6 +67,6 @@ size_t mutt_sasl_plain_msg(char *buf, size_t buflen, const char *cmd, { len = snprintf(buf, buflen, "%s ", cmd); } - len += mutt_b64_encode(buf + len, tmp, tmplen, buflen - len); + len += mutt_b64_encode(tmp, tmplen, buf + len, buflen - len); return len; } diff --git a/email/rfc2047.c b/email/rfc2047.c index 43b21b83a..7b4a1c7b9 100644 --- a/email/rfc2047.c +++ b/email/rfc2047.c @@ -78,7 +78,7 @@ static size_t b_encoder(char *str, const char *buf, size_t buflen, const char *t size_t ret; size_t in_len = MIN(3, buflen); - ret = mutt_b64_encode(encoded, buf, in_len, sizeof(encoded)); + ret = mutt_b64_encode(buf, in_len, encoded, sizeof(encoded)); for (size_t i = 0; i < ret; i++) *str++ = encoded[i]; @@ -397,7 +397,7 @@ static char *decode_word(const char *s, size_t len, enum ContentEncoding enc) { const int olen = 3 * len / 4 + 1; char *out = mutt_mem_malloc(olen); - int dlen = mutt_b64_decode(out, it, olen); + int dlen = mutt_b64_decode(it, out, olen); if (dlen == -1) { FREE(&out); diff --git a/imap/auth_cram.c b/imap/auth_cram.c index 2566f12f5..176fddf6f 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -131,7 +131,7 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapData *idata, const char *method) goto bail; } - len = mutt_b64_decode(obuf, idata->buf + 2, sizeof(obuf)); + len = mutt_b64_decode(idata->buf + 2, obuf, sizeof(obuf)); if (len == -1) { mutt_debug(1, "Error decoding base64 response.\n"); @@ -160,7 +160,7 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapData *idata, const char *method) /* ibuf must be long enough to store the base64 encoding of obuf, * plus the additional debris */ - mutt_b64_encode(ibuf, obuf, strlen(obuf), sizeof(ibuf) - 2); + mutt_b64_encode(obuf, strlen(obuf), ibuf, sizeof(ibuf) - 2); mutt_str_strcat(ibuf, sizeof(ibuf), "\r\n"); mutt_socket_send(idata->conn, ibuf); diff --git a/imap/auth_gss.c b/imap/auth_gss.c index 3dfd9dc42..b7f138dc3 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -180,7 +180,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapData *idata, const char *method) /* now start the security context initialisation loop... */ mutt_debug(2, "Sending credentials\n"); - mutt_b64_encode(buf1, send_token.value, send_token.length, sizeof(buf1) - 2); + mutt_b64_encode(send_token.value, send_token.length, buf1, sizeof(buf1) - 2); gss_release_buffer(&min_stat, &send_token); mutt_str_strcat(buf1, sizeof(buf1), "\r\n"); mutt_socket_send(idata->conn, buf1); @@ -199,7 +199,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapData *idata, const char *method) goto bail; } - request_buf.length = mutt_b64_decode(buf2, idata->buf + 2, sizeof(buf2)); + request_buf.length = mutt_b64_decode(idata->buf + 2, buf2, sizeof(buf2)); request_buf.value = buf2; sec_token = &request_buf; @@ -216,7 +216,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapData *idata, const char *method) goto err_abort_cmd; } - mutt_b64_encode(buf1, send_token.value, send_token.length, sizeof(buf1) - 2); + mutt_b64_encode(send_token.value, send_token.length, buf1, sizeof(buf1) - 2); gss_release_buffer(&min_stat, &send_token); mutt_str_strcat(buf1, sizeof(buf1), "\r\n"); mutt_socket_send(idata->conn, buf1); @@ -234,7 +234,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapData *idata, const char *method) mutt_debug(1, "#2 Error receiving server response.\n"); goto bail; } - request_buf.length = mutt_b64_decode(buf2, idata->buf + 2, sizeof(buf2)); + request_buf.length = mutt_b64_decode(idata->buf + 2, buf2, sizeof(buf2)); request_buf.value = buf2; maj_stat = gss_unwrap(&min_stat, context, &request_buf, &send_token, &cflags, &quality); @@ -282,7 +282,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapData *idata, const char *method) goto err_abort_cmd; } - mutt_b64_encode(buf1, send_token.value, send_token.length, sizeof(buf1) - 2); + mutt_b64_encode(send_token.value, send_token.length, buf1, sizeof(buf1) - 2); mutt_debug(2, "Requesting authorisation as %s\n", idata->conn->account.user); mutt_str_strcat(buf1, sizeof(buf1), "\r\n"); mutt_socket_send(idata->conn, buf1); diff --git a/imap/imap.h b/imap/imap.h index 135dae2fb..fc047fc22 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -115,7 +115,7 @@ void imap_pretty_mailbox(char *path); int imap_wait_keepalive(pid_t pid); void imap_keepalive(void); -void imap_get_parent_path(char *output, const char *path, size_t olen); +void imap_get_parent_path(const char *path, char *buf, size_t buflen); void imap_clean_path(char *path, size_t plen); #endif /* _IMAP_IMAP_H */ diff --git a/imap/imap_private.h b/imap/imap_private.h index d15f99dac..8f68e971f 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -332,7 +332,7 @@ void imap_unquote_string(char *s); void imap_munge_mbox_name(struct ImapData *idata, char *dest, size_t dlen, const char *src); void imap_unmunge_mbox_name(struct ImapData *idata, char *s); int imap_account_match(const struct Account *a1, const struct Account *a2); -void imap_get_parent(char *output, const char *mbox, size_t olen, char delim); +void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen); /* utf7.c */ void imap_utf_encode(struct ImapData *idata, char **s); diff --git a/imap/util.c b/imap/util.c index e665983be..689b9f193 100644 --- a/imap/util.c +++ b/imap/util.c @@ -101,32 +101,32 @@ int imap_expand_path(char *buf, size_t buflen) /** * imap_get_parent - Get an IMAP folder's parent - * @param output Buffer for the result * @param mbox Mailbox whose parent is to be determined - * @param olen Length of the buffer * @param delim Path delimiter + * @param buf Buffer for the result + * @param buflen Length of the buffer */ -void imap_get_parent(char *output, const char *mbox, size_t olen, char delim) +void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen) { int n; /* Make a copy of the mailbox name, but only if the pointers are different */ - if (mbox != output) - mutt_str_strfcpy(output, mbox, olen); + if (mbox != buf) + mutt_str_strfcpy(buf, mbox, buflen); - n = mutt_str_strlen(output); + n = mutt_str_strlen(buf); /* Let's go backwards until the next delimiter * - * If output[n] is a '/', the first n-- will allow us - * to ignore it. If it isn't, then output looks like + * If buf[n] is a '/', the first n-- will allow us + * to ignore it. If it isn't, then buf looks like * "/aaaaa/bbbb". There is at least one "b", so we can't skip * the "/" after the 'a's. * - * If output == '/', then n-- => n == 0, so the loop ends + * If buf == '/', then n-- => n == 0, so the loop ends * immediately */ - for (n--; n >= 0 && output[n] != delim; n--) + for (n--; n >= 0 && buf[n] != delim; n--) ; /* We stopped before the beginning. There is a trailing @@ -135,24 +135,24 @@ void imap_get_parent(char *output, const char *mbox, size_t olen, char delim) if (n > 0) { /* Strip the trailing delimiter. */ - output[n] = '\0'; + buf[n] = '\0'; } else { - output[0] = (n == 0) ? delim : '\0'; + buf[0] = (n == 0) ? delim : '\0'; } } /** * imap_get_parent_path - Get the path of the parent folder - * @param output Buffer for the result * @param path Mailbox whose parent is to be determined - * @param olen Length of the buffer + * @param buf Buffer for the result + * @param buflen Length of the buffer * - * Provided an imap path, returns in output the parent directory if + * Provided an imap path, returns in buf the parent directory if * existent. Else returns the same path. */ -void imap_get_parent_path(char *output, const char *path, size_t olen) +void imap_get_parent_path(const char *path, char *buf, size_t buflen) { struct ImapMbox mx; struct ImapData *idata = NULL; @@ -160,14 +160,14 @@ void imap_get_parent_path(char *output, const char *path, size_t olen) if (imap_parse_path(path, &mx) < 0) { - mutt_str_strfcpy(output, path, olen); + mutt_str_strfcpy(buf, path, buflen); return; } idata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); if (!idata) { - mutt_str_strfcpy(output, path, olen); + mutt_str_strfcpy(buf, path, buflen); return; } @@ -175,10 +175,10 @@ void imap_get_parent_path(char *output, const char *path, size_t olen) imap_fix_path(idata, mx.mbox, mbox, sizeof(mbox)); /* Gets the parent mbox in mbox */ - imap_get_parent(mbox, mbox, sizeof(mbox), idata->delim); + imap_get_parent(mbox, idata->delim, mbox, sizeof(mbox)); /* Returns a fully qualified IMAP url */ - imap_qualify_path(output, olen, &mx, mbox); + imap_qualify_path(buf, buflen, &mx, mbox); FREE(&mx.mbox); } diff --git a/mailbox.c b/mailbox.c index 8fbe1a1fe..365e2acde 100644 --- a/mailbox.c +++ b/mailbox.c @@ -624,7 +624,7 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s, mutt_extract_token(path, s, 0); #ifdef USE_NOTMUCH if (mx_is_notmuch(path->data)) - nm_normalize_uri(buf, path->data, sizeof(buf)); + nm_normalize_uri(path->data, buf, sizeof(buf)); else #endif mutt_str_strfcpy(buf, path->data, sizeof(buf)); @@ -725,7 +725,7 @@ int mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s, #ifdef USE_NOTMUCH if (mx_is_notmuch(path->data)) { - nm_normalize_uri(buf, path->data, sizeof(buf)); + nm_normalize_uri(path->data, buf, sizeof(buf)); } else #endif diff --git a/maildir/mh.c b/maildir/mh.c index 3042b0dcf..7fa01119a 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -2252,23 +2252,23 @@ int mh_sync_mailbox_message(struct Context *ctx, int msgno) /** * maildir_canon_filename - Generate the canonical filename for a Maildir folder - * @param dest Buffer for the result - * @param src Buffer containing source filename - * @param l Length of dest buffer - * @retval ptr Dest buffer + * @param src Buffer containing source filename + * @param buf Buffer for the result + * @param buflen Length of buf buffer + * @retval ptr Buf buffer */ -static char *maildir_canon_filename(char *dest, const char *src, size_t l) +static char *maildir_canon_filename(const char *src, char *buf, size_t buflen) { char *t = strrchr(src, '/'); if (t) src = t + 1; - mutt_str_strfcpy(dest, src, l); - char *u = strrchr(dest, ':'); + mutt_str_strfcpy(buf, src, buflen); + char *u = strrchr(buf, ':'); if (u) *u = '\0'; - return dest; + return buf; } /** @@ -2370,7 +2370,7 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) for (p = md; p; p = p->next) { - maildir_canon_filename(buf, p->h->path, sizeof(buf)); + maildir_canon_filename(p->h->path, buf, sizeof(buf)); p->canon_fname = mutt_str_strdup(buf); mutt_hash_insert(fnames, p->canon_fname, p); } @@ -2379,7 +2379,7 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) for (int i = 0; i < ctx->msgcount; i++) { ctx->hdrs[i]->active = false; - maildir_canon_filename(buf, ctx->hdrs[i]->path, sizeof(buf)); + maildir_canon_filename(ctx->hdrs[i]->path, buf, sizeof(buf)); p = mutt_hash_find(fnames, buf); if (p && p->h) { @@ -2737,7 +2737,7 @@ static FILE *md_open_find_message(const char *folder, const char *unique, while ((de = readdir(dp))) { - maildir_canon_filename(tunique, de->d_name, sizeof(tunique)); + maildir_canon_filename(de->d_name, tunique, sizeof(tunique)); if (mutt_str_strcmp(tunique, unique) == 0) { @@ -2770,7 +2770,7 @@ FILE *maildir_open_find_message(const char *folder, const char *msg, char **newn static unsigned int new_hits = 0, cur_hits = 0; /* simple dynamic optimization */ - maildir_canon_filename(unique, msg, sizeof(unique)); + maildir_canon_filename(msg, unique, sizeof(unique)); FILE *fp = md_open_find_message(folder, unique, new_hits > cur_hits ? "new" : "cur", newname); if (fp || (errno != ENOENT)) diff --git a/mutt/base64.c b/mutt/base64.c index 5ee67e32c..e4ef8780c 100644 --- a/mutt/base64.c +++ b/mutt/base64.c @@ -71,44 +71,44 @@ const int Index64[128] = { /** * mutt_b64_encode - Convert raw bytes to null-terminated base64 string - * @param out Output buffer for the base64 encoded string - * @param cin Input buffer for the raw bytes - * @param len Length of the input buffer - * @param olen Length of the output buffer + * @param in Input buffer for the raw bytes + * @param inlen Length of the input buffer + * @param out Output buffer for the base64 encoded string + * @param outlen Length of the output buffer * @retval num Length of the string written to the output buffer * * This function performs base64 encoding. The resulting string is guaranteed * to be null-terminated. The number of characters up to the terminating - * null-byte is returned (equivalent to calling strlen() on the output buffer + * NUL-byte is returned (equivalent to calling strlen() on the output buffer * after this function returns). */ -size_t mutt_b64_encode(char *out, const char *cin, size_t len, size_t olen) +size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen) { unsigned char *begin = (unsigned char *) out; - const unsigned char *in = (const unsigned char *) cin; + const unsigned char *inu = (const unsigned char *) in; - while ((len >= 3) && (olen > 10)) + while ((inlen >= 3) && (outlen > 10)) { - *out++ = B64Chars[in[0] >> 2]; - *out++ = B64Chars[((in[0] << 4) & 0x30) | (in[1] >> 4)]; - *out++ = B64Chars[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; - *out++ = B64Chars[in[2] & 0x3f]; - olen -= 4; - len -= 3; - in += 3; + *out++ = B64Chars[inu[0] >> 2]; + *out++ = B64Chars[((inu[0] << 4) & 0x30) | (inu[1] >> 4)]; + *out++ = B64Chars[((inu[1] << 2) & 0x3c) | (inu[2] >> 6)]; + *out++ = B64Chars[inu[2] & 0x3f]; + outlen -= 4; + inlen -= 3; + inu += 3; } /* clean up remainder */ - if ((len > 0) && (olen > 4)) + if ((inlen > 0) && (outlen > 4)) { unsigned char fragment; - *out++ = B64Chars[in[0] >> 2]; - fragment = (in[0] << 4) & 0x30; - if (len > 1) - fragment |= in[1] >> 4; + *out++ = B64Chars[inu[0] >> 2]; + fragment = (inu[0] << 4) & 0x30; + if (inlen > 1) + fragment |= inu[1] >> 4; *out++ = B64Chars[fragment]; - *out++ = (len < 2) ? '=' : B64Chars[(in[1] << 2) & 0x3c]; + *out++ = (inlen < 2) ? '=' : B64Chars[(inu[1] << 2) & 0x3c]; *out++ = '='; } *out = '\0'; @@ -117,8 +117,8 @@ size_t mutt_b64_encode(char *out, const char *cin, size_t len, size_t olen) /** * mutt_b64_decode - Convert null-terminated base64 string to raw bytes - * @param out Output buffer for the raw bytes * @param in Input buffer for the null-terminated base64-encoded string + * @param out Output buffer for the raw bytes * @param olen Length of the output buffer * @retval num Success, bytes written * @retval -1 Error @@ -127,7 +127,7 @@ size_t mutt_b64_encode(char *out, const char *cin, size_t len, size_t olen) * null-terminated. If the input buffer contains invalid base64 characters, * this function returns -1. */ -int mutt_b64_decode(char *out, const char *in, size_t olen) +int mutt_b64_decode(const char *in, char *out, size_t olen) { int len = 0; unsigned char digit4; diff --git a/mutt/base64.h b/mutt/base64.h index d6dc45edb..d2a6ed799 100644 --- a/mutt/base64.h +++ b/mutt/base64.h @@ -27,7 +27,7 @@ extern const int Index64[]; #define base64val(c) Index64[(unsigned int) (c)] -int mutt_b64_decode(char *out, const char *in, size_t olen); -size_t mutt_b64_encode(char *out, const char *cin, size_t len, size_t olen); +int mutt_b64_decode(const char *in, char *out, size_t olen); +size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen); #endif /* _MUTT_BASE64_H */ diff --git a/mutt/file.c b/mutt/file.c index 94cacb0ac..34bc01395 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -660,43 +660,43 @@ char *mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags) /** * mutt_file_quote_filename - Quote a filename to survive the shell's quoting rules - * @param d Buffer for the result - * @param l Length of buffer - * @param f String to convert + * @param filename String to convert + * @param buf Buffer for the result + * @param buflen Length of buffer * @retval num Bytes written to the buffer * * From the Unix programming FAQ by way of Liviu. */ -size_t mutt_file_quote_filename(char *d, size_t l, const char *f) +size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen) { size_t j = 0; - if (!f) + if (!filename) { - *d = '\0'; + *buf = '\0'; return 0; } /* leave some space for the trailing characters. */ - l -= 6; + buflen -= 6; - d[j++] = '\''; + buf[j++] = '\''; - for (size_t i = 0; (j < l) && f[i]; i++) + for (size_t i = 0; (j < buflen) && filename[i]; i++) { - if ((f[i] == '\'') || (f[i] == '`')) + if ((filename[i] == '\'') || (filename[i] == '`')) { - d[j++] = '\''; - d[j++] = '\\'; - d[j++] = f[i]; - d[j++] = '\''; + buf[j++] = '\''; + buf[j++] = '\\'; + buf[j++] = filename[i]; + buf[j++] = '\''; } else - d[j++] = f[i]; + buf[j++] = filename[i]; } - d[j++] = '\''; - d[j] = '\0'; + buf[j++] = '\''; + buf[j] = '\0'; return j; } @@ -1250,7 +1250,7 @@ void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, con { char tmp[PATH_MAX]; - mutt_file_quote_filename(tmp, sizeof(tmp), src); + mutt_file_quote_filename(src, tmp, sizeof(tmp)); mutt_file_expand_fmt(dest, destlen, fmt, tmp); } diff --git a/mutt/file.h b/mutt/file.h index 8f5dba3f3..85fab0f39 100644 --- a/mutt/file.h +++ b/mutt/file.h @@ -54,7 +54,7 @@ int mutt_file_mkdir(const char *path, mode_t mode); FILE * mutt_file_mkstemp_full(const char *file, int line, const char *func); #define mutt_file_mkstemp() mutt_file_mkstemp_full(__FILE__, __LINE__, __func__) int mutt_file_open(const char *path, int flags); -size_t mutt_file_quote_filename(char *d, size_t l, const char *f); +size_t mutt_file_quote_filename(const char *filename, char *buf, size_t buflen); char * mutt_file_read_keyword(const char *file, char *buf, size_t buflen); char * mutt_file_read_line(char *s, size_t *size, FILE *fp, int *line, int flags); int mutt_file_rename(char *oldfile, char *newfile); diff --git a/muttlib.c b/muttlib.c index 2c3c0889c..e6be323ec 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1514,7 +1514,7 @@ void mutt_get_parent_path(char *path, char *buf, size_t buflen) { #ifdef USE_IMAP if (mx_is_imap(path)) - imap_get_parent_path(buf, path, buflen); + imap_get_parent_path(path, buf, buflen); else #endif #ifdef USE_NOTMUCH diff --git a/ncrypt/pgpinvoke.c b/ncrypt/pgpinvoke.c index b195fd0a6..1a3dbadfb 100644 --- a/ncrypt/pgpinvoke.c +++ b/ncrypt/pgpinvoke.c @@ -402,7 +402,7 @@ void pgp_class_invoke_import(const char *fname) char cmd[HUGE_STRING]; struct PgpCommandContext cctx = { 0 }; - mutt_file_quote_filename(tmp_fname, sizeof(tmp_fname), fname); + mutt_file_quote_filename(fname, tmp_fname, sizeof(tmp_fname)); cctx.fname = tmp_fname; if (PgpSignAs && *PgpSignAs) cctx.signas = PgpSignAs; @@ -437,7 +437,7 @@ void pgp_class_invoke_getkeys(struct Address *addr) *tmp = '\0'; mutt_addrlist_to_local(addr); mutt_addr_write_single(tmp, sizeof(tmp), addr, false); - mutt_file_quote_filename(buf, sizeof(buf), tmp); + mutt_file_quote_filename(tmp, buf, sizeof(buf)); addr->personal = personal; @@ -533,7 +533,7 @@ pid_t pgp_invoke_list_keys(FILE **pgpin, FILE **pgpout, FILE **pgperr, struct ListNode *np = NULL; STAILQ_FOREACH(np, hints, entries) { - mutt_file_quote_filename(quoted, sizeof(quoted), (char *) np->data); + mutt_file_quote_filename((char *) np->data, quoted, sizeof(quoted)); snprintf(tmpuids, sizeof(tmpuids), "%s %s", uids, quoted); strcpy(uids, tmpuids); } diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 4f74c35b9..028365005 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -229,7 +229,7 @@ static const char *fmt_smime_command(char *buf, size_t buflen, size_t col, int c mutt_str_strfcpy(path, SmimeCaLocation, sizeof(path)); mutt_expand_path(path, sizeof(path)); - mutt_file_quote_filename(buf1, sizeof(buf1), path); + mutt_file_quote_filename(path, buf1, sizeof(buf1)); if (stat(path, &sb) != 0 || !S_ISDIR(sb.st_mode)) snprintf(buf2, sizeof(buf2), "-CAfile %s", buf1); diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 50754f933..a216745f9 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1520,15 +1520,15 @@ static int update_header_flags(struct Context *ctx, struct Header *hdr, const ch /** * rename_maildir_filename - Rename a Maildir file - * @param old Old path - * @param newpath Buffer for new path - * @param newsz Length of buffer - * @param h Email Header + * @param old Old path + * @param buf Buffer for new path + * @param buflen Length of buffer + * @param h Email Header * @retval 0 Success, renamed * @retval 1 Success, no change * @retval -1 Failure */ -static int rename_maildir_filename(const char *old, char *newpath, size_t newsz, +static int rename_maildir_filename(const char *old, char *buf, size_t buflen, struct Header *h) { char filename[PATH_MAX]; @@ -1560,15 +1560,15 @@ static int rename_maildir_filename(const char *old, char *newpath, size_t newsz, /* compose new flags */ maildir_flags(suffix, sizeof(suffix), h); - snprintf(newpath, newsz, "%s/%s/%s%s", folder, + snprintf(buf, buflen, "%s/%s/%s%s", folder, (h->read || h->old) ? "cur" : "new", filename, suffix); - if (strcmp(old, newpath) == 0) + if (strcmp(old, buf) == 0) return 1; - if (rename(old, newpath) != 0) + if (rename(old, buf) != 0) { - mutt_debug(1, "nm: rename(2) failed %s -> %s\n", old, newpath); + mutt_debug(1, "nm: rename(2) failed %s -> %s\n", old, buf); return -1; } @@ -1943,11 +1943,11 @@ char *nm_uri_from_query(struct Context *ctx, char *buf, size_t buflen) /** * nm_normalize_uri - takes a notmuch URI, parses it and reformat it in a canonical way - * @param new_uri allocated string receiving the reformatted URI - * @param orig_uri original URI to be parsed - * @param new_uri_sz size of the allocated new_uri string - * @retval true if new_uri contains a normalized version of the query - * @retval false if orig_uri contains an invalid query + * @param uri Original URI to be parsed + * @param buf Buffer for the reformatted URI + * @param buflen Size of the buffer + * @retval true if buf contains a normalized version of the query + * @retval false if uri contains an invalid query * * This function aims at making notmuch searches URI representations deterministic, * so that when comparing two equivalent searches they will be the same. It works @@ -1957,14 +1957,14 @@ char *nm_uri_from_query(struct Context *ctx, char *buf, size_t buflen) * It's aimed to be used by mailbox when parsing the virtual_mailboxes to make the * parsed user written search strings comparable to the internally generated ones. */ -bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz) +bool nm_normalize_uri(const char *uri, char *buf, size_t buflen) { - mutt_debug(2, "(%s)\n", orig_uri); - char buf[PATH_MAX]; + mutt_debug(2, "(%s)\n", uri); + char tmp[PATH_MAX]; int rc = -1; struct Context tmp_ctx = { 0 }; - struct NmCtxData *tmp_ctxdata = new_ctxdata(orig_uri); + struct NmCtxData *tmp_ctxdata = new_ctxdata(uri); if (!tmp_ctxdata) return false; @@ -1979,14 +1979,14 @@ bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz) mutt_debug(2, "#2 () -> db_query: %s\n", tmp_ctxdata->db_query); - mutt_str_strfcpy(buf, tmp_ctxdata->db_query, sizeof(buf)); + mutt_str_strfcpy(tmp, tmp_ctxdata->db_query, sizeof(tmp)); - if (!nm_uri_from_query(&tmp_ctx, buf, sizeof(buf))) + if (!nm_uri_from_query(&tmp_ctx, tmp, sizeof(tmp))) goto gone; - strncpy(new_uri, buf, new_uri_sz); + strncpy(buf, tmp, buflen); - mutt_debug(2, "#3 (%s) -> %s\n", orig_uri, new_uri); + mutt_debug(2, "#3 (%s) -> %s\n", uri, buf); rc = 0; gone: @@ -1995,7 +1995,7 @@ gone: FREE(&tmp_ctxdata); if (rc < 0) { - mutt_error(_("failed to parse notmuch uri: %s"), orig_uri); + mutt_error(_("failed to parse notmuch uri: %s"), uri); mutt_debug(2, "() -> error\n"); return false; } diff --git a/notmuch/mutt_notmuch.h b/notmuch/mutt_notmuch.h index f43faa70c..56f79c2aa 100644 --- a/notmuch/mutt_notmuch.h +++ b/notmuch/mutt_notmuch.h @@ -55,7 +55,7 @@ int nm_read_entire_thread(struct Context *ctx, struct Header *h); char *nm_header_get_folder(struct Header *h); int nm_update_filename(struct Context *ctx, const char *old, const char *new, struct Header *h); -bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz); +bool nm_normalize_uri(const char *uri, char *buf, size_t buflen); char *nm_uri_from_query(struct Context *ctx, char *buf, size_t buflen); bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr); diff --git a/remailer.c b/remailer.c index 06e981958..a07caba9b 100644 --- a/remailer.c +++ b/remailer.c @@ -830,7 +830,7 @@ int mix_send_message(struct ListHead *chain, const char *tempfile) STAILQ_FOREACH(np, chain, entries) { mutt_str_strfcpy(tmp, cmd, sizeof(tmp)); - mutt_file_quote_filename(cd_quoted, sizeof(cd_quoted), np->data); + mutt_file_quote_filename(np->data, cd_quoted, sizeof(cd_quoted)); snprintf(cmd, sizeof(cmd), "%s%s%s", tmp, (np == STAILQ_FIRST(chain)) ? " -l " : ",", cd_quoted); } diff --git a/rfc1524.c b/rfc1524.c index 3a9b0b5d2..2ed57ec1f 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -108,16 +108,16 @@ int rfc1524_expand_command(struct Body *a, char *filename, char *type, char *com if (MailcapSanitize) mutt_file_sanitize_filename(pvalue, false); - y += mutt_file_quote_filename(buf + y, sizeof(buf) - y, pvalue); + y += mutt_file_quote_filename(pvalue, buf + y, sizeof(buf) - y); } else if (command[x] == 's' && filename) { - y += mutt_file_quote_filename(buf + y, sizeof(buf) - y, filename); + y += mutt_file_quote_filename(filename, buf + y, sizeof(buf) - y); needspipe = false; } else if (command[x] == 't') { - y += mutt_file_quote_filename(buf + y, sizeof(buf) - y, type2); + y += mutt_file_quote_filename(type2, buf + y, sizeof(buf) - y); } x++; } diff --git a/sendlib.c b/sendlib.c index bf642b98e..840a00926 100644 --- a/sendlib.c +++ b/sendlib.c @@ -269,7 +269,7 @@ static void b64_flush(struct B64Context *ctx, FILE *fout) /* ret should always be equal to 4 here, because ctx->size * is a value between 1 and 3 (included), but let's not hardcode it * and prefer the return value of the function */ - ret = mutt_b64_encode(encoded, ctx->buffer, ctx->size, sizeof(encoded)); + ret = mutt_b64_encode(ctx->buffer, ctx->size, encoded, sizeof(encoded)); for (size_t i = 0; i < ret; i++) { fputc(encoded[i], fout); diff --git a/test/base64.c b/test/base64.c index f8b77dbc7..4b0b47f59 100644 --- a/test/base64.c +++ b/test/base64.c @@ -11,7 +11,7 @@ static const char encoded[] = "SGVsbG8="; void test_base64_encode(void) { char buffer[16]; - size_t len = mutt_b64_encode(buffer, clear, sizeof(clear) - 1, sizeof(buffer)); + size_t len = mutt_b64_encode(clear, sizeof(clear) - 1, buffer, sizeof(buffer)); if (!TEST_CHECK(len == sizeof(encoded) - 1)) { TEST_MSG("Expected: %zu", sizeof(encoded) - 1); @@ -27,7 +27,7 @@ void test_base64_encode(void) void test_base64_decode(void) { char buffer[16]; - int len = mutt_b64_decode(buffer, encoded, sizeof(buffer)); + int len = mutt_b64_decode(encoded, buffer, sizeof(buffer)); if (!TEST_CHECK(len == sizeof(clear) - 1)) { TEST_MSG("Expected: %zu", sizeof(clear) - 1); @@ -50,7 +50,7 @@ void test_base64_lengths(void) int declen; /* Encoding a zero-length string should fail */ - enclen = mutt_b64_encode(out1, in, 0, 32); + enclen = mutt_b64_encode(in, 0, out1, 32); if (!TEST_CHECK(enclen == 0)) { TEST_MSG("Expected: %zu", 0); @@ -59,7 +59,7 @@ void test_base64_lengths(void) /* Decoding a zero-length string should fail, too */ out1[0] = '\0'; - declen = mutt_b64_decode(out2, out1, sizeof(out2)); + declen = mutt_b64_decode(out1, out2, sizeof(out2)); if (!TEST_CHECK(declen == -1)) { TEST_MSG("Expected: %zu", -1); @@ -69,14 +69,14 @@ void test_base64_lengths(void) /* Encode one to eight bytes, check the lengths of the returned string */ for (size_t i = 1; i <= 8; ++i) { - enclen = mutt_b64_encode(out1, in, i, 32); + enclen = mutt_b64_encode(in, i, out1, 32); size_t exp = ((i + 2) / 3) << 2; if (!TEST_CHECK(enclen == exp)) { TEST_MSG("Expected: %zu", exp); TEST_MSG("Actual : %zu", enclen); } - declen = mutt_b64_decode(out2, out1, sizeof(out2)); + declen = mutt_b64_decode(out1, out2, sizeof(out2)); if (!TEST_CHECK(declen == i)) { TEST_MSG("Expected: %zu", i); -- 2.50.1