Skip to content

Commit d1510ee

Browse files
committed
patch 8.2.2299: Vim9: invalid memory access making error message flaky
Problem: Vim9: invalid memory access making error message flaky. Solution: Do not check cmd_argt for CMD_USER. (issue #7467)
1 parent cef1270 commit d1510ee

6 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ EXTERN char e_undefined_variable_str[]
1616
EXTERN char e_undefined_variable_char_str[]
1717
INIT(= N_("E121: Undefined variable: %c:%s"));
1818
#endif
19+
EXTERN char e_ambiguous_use_of_user_defined_command[]
20+
INIT(= N_("E464: Ambiguous use of user-defined command"));
1921
EXTERN char e_invalid_command[]
2022
INIT(= N_("E476: Invalid command"));
2123
#ifdef FEAT_EVAL

src/ex_docmd.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ do_one_cmd(
20252025
if (p == NULL)
20262026
{
20272027
if (!ea.skip)
2028-
errormsg = _("E464: Ambiguous use of user-defined command");
2028+
errormsg = _(e_ambiguous_use_of_user_defined_command);
20292029
goto doend;
20302030
}
20312031
// Check for wrong commands.
@@ -3531,9 +3531,11 @@ find_ex_command(
35313531
eap->cmdidx = CMD_finally;
35323532

35333533
#ifdef FEAT_EVAL
3534-
if (eap->cmdidx != CMD_SIZE && in_vim9script()
3534+
if (eap->cmdidx < CMD_SIZE
3535+
&& in_vim9script()
35353536
&& !IS_WHITE_OR_NUL(*p) && *p != '\n' && *p != '!'
3536-
&& (cmdnames[eap->cmdidx].cmd_argt & EX_NONWHITE_OK) == 0)
3537+
&& (eap->cmdidx < 0 ||
3538+
(cmdnames[eap->cmdidx].cmd_argt & EX_NONWHITE_OK) == 0))
35373539
{
35383540
semsg(_(e_command_not_followed_by_white_space_str), eap->cmd);
35393541
eap->cmdidx = CMD_SIZE;

src/testdir/test_vim9_cmd.vim

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,24 @@ def Test_f_args()
771771
CheckScriptSuccess(lines)
772772
enddef
773773

774+
def Test_user_command_comment()
775+
command -nargs=1 Comd echom <q-args>
776+
777+
var lines =<< trim END
778+
vim9script
779+
Comd # comment
780+
END
781+
CheckScriptSuccess(lines)
782+
783+
lines =<< trim END
784+
vim9script
785+
Comd# comment
786+
END
787+
CheckScriptFailure(lines, 'E1144:')
788+
789+
delcommand Comd
790+
enddef
791+
774792
def Test_star_command()
775793
var lines =<< trim END
776794
vim9script
@@ -798,12 +816,14 @@ def Test_cmd_argument_without_colon()
798816
enddef
799817

800818
def Test_ambiguous_user_cmd()
819+
command Cmd1 eval 0
820+
command Cmd2 eval 0
801821
var lines =<< trim END
802-
com Cmd1 eval 0
803-
com Cmd2 eval 0
804822
Cmd
805823
END
806-
CheckScriptFailure(lines, 'E464:')
824+
CheckDefAndScriptFailure(lines, 'E464:', 1)
825+
delcommand Cmd1
826+
delcommand Cmd2
807827
enddef
808828

809829
def Test_command_not_recognized()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2299,
753755
/**/
754756
2298,
755757
/**/

src/vim9compile.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7797,6 +7797,13 @@ compile_def_function(ufunc_T *ufunc, int check_return_type, cctx_T *outer_cctx)
77977797
: (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local,
77987798
&cctx);
77997799

7800+
if (p == NULL)
7801+
{
7802+
if (cctx.ctx_skip != SKIP_YES)
7803+
emsg(_(e_ambiguous_use_of_user_defined_command));
7804+
goto erret;
7805+
}
7806+
78007807
if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
78017808
{
78027809
if (cctx.ctx_skip == SKIP_YES)

src/vim9execute.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,6 +3054,7 @@ call_def_function(
30543054
goto failed;
30553055
++ectx.ec_stack.ga_len;
30563056
tv = STACK_TV_BOT(-1);
3057+
ea.addr_count = 0;
30573058
ea.addr_type = ADDR_LINES;
30583059
ea.cmd = iptr->isn_arg.string;
30593060
if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL)

0 commit comments

Comments
 (0)