diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 479b6a24cf..cb0ebf0d6e 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2777,9 +2777,11 @@ int parse_command_modifiers(exarg_T *eap, const char **errormsg, cmdmod_T *cmod, size_t len = strlen(cmd_start); // Special case: empty command uses "+": - // "'<,'>mods" -> "mods'<,'>+ + // "'<,'>mods" -> "mods *+ + // Use "*" instead of "'<,'>" to avoid the command getting + // longer, in case is was allocated. memmove(orig_cmd, cmd_start, len); - strcpy(orig_cmd + len, "'<,'>+"); + xmemcpyz(orig_cmd + len, S_LEN(" *+")); } else { memmove(cmd_start - 5, cmd_start, (size_t)(eap->cmd - cmd_start)); eap->cmd -= 5; diff --git a/test/old/testdir/test_cmdline.vim b/test/old/testdir/test_cmdline.vim index f5955a58cf..0a2b7b6141 100644 --- a/test/old/testdir/test_cmdline.vim +++ b/test/old/testdir/test_cmdline.vim @@ -2561,6 +2561,14 @@ func Test_cmdwin_insert_mode_close() call assert_equal(1, winnr('$')) endfunc +func Test_cmdwin_ex_mode_with_modifier() + " this was accessing memory after allocated text in Ex mode + new + call setline(1, ['some', 'text', 'lines']) + silent! call feedkeys("gQnormal vq:atopleft\\\", 'xt') + bwipe! +endfunc + " test that ";" works to find a match at the start of the first line func Test_zero_line_search() new