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".
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