Re: [PATCH] Change mutt_buffer_concatn_path() to use fixed algorithm.
Alejandro Colomar via Mutt-dev <[email protected]> Tue, 19 May 2026 12:15:20 +0200
| Newsgroups | gmane.mail.mutt.devel |
|---|---|
| Message-ID | <agw3r9HJQDjyY6qs@devuan> |
Hi Kvein,
On 2026-05-19T13:56:45+0800, Kevin J. McCarthy wrote:
> Revise it to use mutt_buffer_concat_path(), which was fixed in commit
> 048f4ae2.
> ---
>
> Derek Martin noticed this function was using an incorrect algorithm too.
>
> The function is only called in one place, mutt_complete() which handles
> command prompt completion of path.
>
> *** This commit, however does cause a CHANGE OF BEHAVIOR. ***
>
> When the dir part is empty, the old algorithm concatn_path combines:
> "" + "dir" => "dir"
>
> The new algorithm, now using mutt_buffer_concat_path, combines:
> "" + "dir" => "/dir"
>
> To see the change in mutt, start up mutt and
> - :unset folder<enter>
> - <change-folder>
> - At the prompt: Open mailbox ('?' for list):
> =usr/
> then hit Tab twice.
>
> Before this commit mutt will try to expand "usr" in your cwd.
> After this commit mutt will try to expand "/usr".
Doesn't = mean it's a relative path? Is it correct to interpret it as
/usr? I'm not very familiar with how these paths work, so I might be
completely wrong.
Have a lovely day!
Alex
>
> You can also see the difference if you start mutt from your homedir, and
> subsitute "usr/" for a directory in your homedir, such as "Documents/".
>
> This is an edge case, but I wanted to bring it up for discussion before
> making this change.
>
> muttlib.c | 20 +++++++++++++-------
> 1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/muttlib.c b/muttlib.c
> index baef6038..df882002 100644
> --- a/muttlib.c
> +++ b/muttlib.c
> @@ -1421,19 +1421,25 @@ void mutt_buffer_concat_path(BUFFER *d, const char *dir, const char *fname)
> }
>
> /*
> - * Write the concatened pathname (dir + "/" + fname) into dst.
> - * The slash is omitted when dir or fname is of 0 length.
> + * Write the concatened pathname (dir + "/" + fname) into dst,
> + * respecting the size limits passed in.
> */
> void mutt_buffer_concatn_path(BUFFER *dst, const char *dir, size_t dirlen,
> const char *fname, size_t fnamelen)
> {
> - mutt_buffer_clear(dst);
> + BUFFER *dirbuf, *fnamebuf;
> +
> + dirbuf = mutt_buffer_pool_get();
> + fnamebuf = mutt_buffer_pool_get();
> +
> if (dirlen)
> - mutt_buffer_addstr_n(dst, dir, dirlen);
> - if (dirlen && fnamelen)
> - mutt_buffer_addch(dst, '/');
> + mutt_buffer_addstr_n(dirbuf, dir, dirlen);
> if (fnamelen)
> - mutt_buffer_addstr_n(dst, fname, fnamelen);
> + mutt_buffer_addstr_n(fnamebuf, fname, fnamelen);
> + mutt_buffer_concat_path(dst, mutt_b2s(dirbuf), mutt_b2s(fnamebuf));
> +
> + mutt_buffer_pool_release(&dirbuf);
> + mutt_buffer_pool_release(&fnamebuf);
> }
>
> const char *mutt_getcwd(BUFFER *cwd)
> --
> 2.54.0
>
--
<https://www.alejandro-colomar.es>
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmoMODcACgkQ64mZXMKQ wql3zQ//etzjnxKz4x8AtZfJtFNNq3AwR76U+w9IjDA978kncl/tQ/Z7+YQEYd1l W4EsJNGP1/4pAM0dJvSBdb9EOMs9wJjy7VmJr8XQl6rvOQTjHVaR18fGa8q00fyK zGO6W7RPzcwCF+KpRj4Vik7DS8CBJsesQsm+gF0h0gQVsz/2enRxCPt5AchwzWDk 2J7DiaZD9/+hPI3J+Uf0+yR2wlxxb5cjZw+wQ04YZppAITiYHBMD37w7FHqoxzWt 0YaeF+LTVuhEBUZOCZinxhjbCVjRd2oAvszA2wK70WTLaUO/kciswnv4vKYHvz16 goydH5n6jL2lmSgVuTSAzc7rEtJkTbt42CNsd//VEYAPC8Lox4Ymp670tZOwGUn/ 8x98703dHussONuA4iq+8TciqeprxC0uBC6rOKuaDy8BIVvTRFEYkbt6rAQuPRzB R07aJy4kumbP1BatLlMbvqS7Kw9F/SmkHuTobtVEGkli8KBeNHgfk1958v776cSF ZFAdFSRy/7CAHTbIoncp+8UvWezGLZwMqhhOl2cfS7MjwU5TX9rxrwTShnYidDby 0QkeooBksd3qzLPkyco3tjGePtLCinWR/8YahtGonPJlVtrPTy+/BoCCnSbdhlxE H4+zNBi0IiceQ7E73TRTA+nanTNuKmUlevB57Md3SNzNSdU3wzs= =UD/f -----END PGP SIGNATURE-----