You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Running "browse tabnew" command in TUI MacVim crashes Vim #1107
I am not able to build MacVim with debug symbols enabled and load it in lldb.
I set CFLAGS to "-g -O0" in Makefile and built Vim. Still the generated Vim
binary under the MacVim/build/Release/MacVim.app/Contents/MacOS
directory didn't have the debug symbols.
I am able to build the regular Vim with debug symbols enabled on MacOS, Linux
and MS-Windows. How do I build MacVim with debug symbols enabled, load it
in lldb and step through the code?
This issue is caused by fname_case() trying to copy a string to
a read-only string. The relevant lines are 2514 in ex_cmds.c and
6139 in ex_docmd.c.
If I use vim_strsave() to create a copy of the "." string, then the
crash is not seen. But there is a memory leak now. I need to
come up with a fix to free this memory.
The patch is below:
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index c61f57533..e2396c8c5 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2511,7 +2511,7 @@ do_ecmd(
// No browsing supported but we do have the file explorer:
// Edit the directory.
if (ffname == NULL || !mch_isdir(ffname))
- ffname = (char_u *)".";
+ ffname = vim_strsave((char_u *)".");
}
else
{
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index bc01b69c7..4ab0b0a6f 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -6117,7 +6117,7 @@ ex_splitview(exarg_T *eap)
// No browsing supported but we do have the file explorer:
// Edit the directory.
if (*eap->arg == NUL || !mch_isdir(eap->arg))
- eap->arg = (char_u *)".";
+ eap->arg = vim_strsave((char_u *)".");
}
else
{
Maybe it can use stack, I think because:
The return value of do_browse() in the opposite side block is finally freed in the end of the function.
Thus, also the values of eap->arg and ffname just have to exist only during the function.
--- a/src/ex_cmds.c+++ b/src/ex_cmds.c@@ -2465,6 +2465,7 @@ do_ecmd(
bufref_T old_curbuf;
char_u *free_fname = NULL;
#ifdef FEAT_BROWSE
+ char_u dot_path[] = ".";
char_u *browse_file = NULL;
#endif
int retval = FAIL;
@@ -2511,7 +2512,7 @@ do_ecmd(
// No browsing supported but we do have the file explorer:
// Edit the directory.
if (ffname == NULL || !mch_isdir(ffname))
- ffname = (char_u *)".";+ ffname = dot_path;
}
else
{
--- a/src/ex_docmd.c+++ b/src/ex_docmd.c@@ -6084,6 +6084,7 @@ ex_splitview(exarg_T *eap)
char_u *fname = NULL;
#endif
#ifdef FEAT_BROWSE
+ char_u dot_path[] = ".";
int browse_flag = cmdmod.browse;
#endif
int use_tab = eap->cmdidx == CMD_tabedit
@@ -6136,7 +6137,7 @@ ex_splitview(exarg_T *eap)
// No browsing supported but we do have the file explorer:
// Edit the directory.
if (*eap->arg == NUL || !mch_isdir(eap->arg))
- eap->arg = (char_u *)".";+ eap->arg = dot_path;
}
else
{
I like @ichizok's version, and it also removes the insidious const cast here (which cast "." from const char_u * to char_u *) which is the root source of the bug.
Also, seems like there is a coverage gap here in that no test is exercising :browse. But maybe even with a test this wouldn't have been caught as it relies on certain settings to be set.
I agree. We can go with the changes from @ichizok. Can you create a PR in the upstream Vim repository?
It will be difficult to create a test for this as this needs a GUI Vim running in a Terminal on MS-Windows
or MacOS. The GUI build for MacOS doesn't work with the upstream Vim source.
Activity
ychin commentedon Oct 11, 2020
Just reproduced this. Thanks for the report.
yegappan commentedon Oct 11, 2020
The following commands also crash Vim: "browse enew", "browse split",
"browse edit", "browse view", "browse vsplit", "browse tabedit", "browse diffsplit",
"browse open", "browse visual", "browse vsplit".
Most probably the fix is the same for all of these commands.
The backtrace for one of the crashes is:
I am not able to build MacVim with debug symbols enabled and load it in lldb.
I set CFLAGS to "-g -O0" in Makefile and built Vim. Still the generated Vim
binary under the MacVim/build/Release/MacVim.app/Contents/MacOS
directory didn't have the debug symbols.
I am able to build the regular Vim with debug symbols enabled on MacOS, Linux
and MS-Windows. How do I build MacVim with debug symbols enabled, load it
in lldb and step through the code?
ichizok commentedon Oct 12, 2020
It can reproduce in Linux and other OS by defining
USE_FNAME_CASEon build (with GUI), thus it appears an upstream problem.ichizok commentedon Oct 12, 2020
Conditions that causes the problem:
+browsefeature (e.g. built with GUI)augroup FileExploreris defined (e.g. loaded netrw plugin)USE_FNAME_CASEmacro is defined (e.g. on macOS, Windows)ychin commentedon Oct 12, 2020
Regarding building for debugging, @yegappan , see https://github.com/macvim-dev/macvim/wiki/Building. In particular, this should work:
ychin commentedon Oct 12, 2020
Just looking at older builds, seems like most of them suffer the same issue. I think this is a pretty old bug. At least 1 year old.
yegappan commentedon Oct 12, 2020
This issue is caused by fname_case() trying to copy a string to
a read-only string. The relevant lines are 2514 in ex_cmds.c and
6139 in ex_docmd.c.
If I use vim_strsave() to create a copy of the "." string, then the
crash is not seen. But there is a memory leak now. I need to
come up with a fix to free this memory.
The patch is below:
yegappan commentedon Oct 13, 2020
An updated patch that fixes this problem without a memory leak is:
ichizok commentedon Oct 13, 2020
Maybe it can use stack, I think because:
The return value of
do_browse()in the opposite side block is finally freed in the end of the function.Thus, also the values of
eap->argandffnamejust have to exist only during the function.ychin commentedon Oct 13, 2020
I like @ichizok's version, and it also removes the insidious const cast here (which cast
"."fromconst char_u *tochar_u *) which is the root source of the bug.Can we move the discussion to https://github.com/vim/vim though?
ychin commentedon Oct 13, 2020
Also, seems like there is a coverage gap here in that no test is exercising
:browse. But maybe even with a test this wouldn't have been caught as it relies on certain settings to be set.yegappan commentedon Oct 13, 2020
I agree. We can go with the changes from @ichizok. Can you create a PR in the upstream Vim repository?
It will be difficult to create a test for this as this needs a GUI Vim running in a Terminal on MS-Windows
or MacOS. The GUI build for MacOS doesn't work with the upstream Vim source.
yegappan commentedon Oct 13, 2020
This issue has now been fixed in the upstream by 8.2.1842.
ychin commentedon Oct 13, 2020
Thanks. Will be merged from upstream.
MacVim Snapshot 167
MacVim Snapshot 168