Patch 8.2.2299
Problem:    Vim9: invalid memory access making error message flaky.
Solution:   Do not check cmd_argt for CMD_USER. (issue #7467)
Files:      src/ex_docmd.c, src/vim9execute.c, src/errors.h,
            src/vim9compile.c, src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2298/src/ex_docmd.c      2021-01-04 12:41:49.503891371 +0100
--- src/ex_docmd.c      2021-01-04 15:41:22.305416266 +0100
***************
*** 2025,2031 ****
      if (p == NULL)
      {
        if (!ea.skip)
!           errormsg = _("E464: Ambiguous use of user-defined command");
        goto doend;
      }
      // Check for wrong commands.
--- 2025,2031 ----
      if (p == NULL)
      {
        if (!ea.skip)
!           errormsg = _(e_ambiguous_use_of_user_defined_command);
        goto doend;
      }
      // Check for wrong commands.
***************
*** 3531,3539 ****
        eap->cmdidx = CMD_finally;
  
  #ifdef FEAT_EVAL
!     if (eap->cmdidx != CMD_SIZE && in_vim9script()
            && !IS_WHITE_OR_NUL(*p) && *p != '\n' && *p != '!'
!           && (cmdnames[eap->cmdidx].cmd_argt & EX_NONWHITE_OK) == 0)
      {
        semsg(_(e_command_not_followed_by_white_space_str), eap->cmd);
        eap->cmdidx = CMD_SIZE;
--- 3531,3541 ----
        eap->cmdidx = CMD_finally;
  
  #ifdef FEAT_EVAL
!     if (eap->cmdidx < CMD_SIZE
!           && in_vim9script()
            && !IS_WHITE_OR_NUL(*p) && *p != '\n' && *p != '!'
!           && (eap->cmdidx < 0 ||
!               (cmdnames[eap->cmdidx].cmd_argt & EX_NONWHITE_OK) == 0))
      {
        semsg(_(e_command_not_followed_by_white_space_str), eap->cmd);
        eap->cmdidx = CMD_SIZE;
*** ../vim-8.2.2298/src/vim9execute.c   2021-01-04 10:47:21.698153964 +0100
--- src/vim9execute.c   2021-01-04 15:34:38.271057083 +0100
***************
*** 3054,3059 ****
--- 3054,3060 ----
                        goto failed;
                    ++ectx.ec_stack.ga_len;
                    tv = STACK_TV_BOT(-1);
+                   ea.addr_count = 0;
                    ea.addr_type = ADDR_LINES;
                    ea.cmd = iptr->isn_arg.string;
                    if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL)
*** ../vim-8.2.2298/src/errors.h        2021-01-01 19:17:52.293976798 +0100
--- src/errors.h        2021-01-04 15:41:31.253381270 +0100
***************
*** 16,21 ****
--- 16,23 ----
  EXTERN char e_undefined_variable_char_str[]
        INIT(= N_("E121: Undefined variable: %c:%s"));
  #endif
+ EXTERN char e_ambiguous_use_of_user_defined_command[]
+       INIT(= N_("E464: Ambiguous use of user-defined command"));
  EXTERN char e_invalid_command[]
        INIT(= N_("E476: Invalid command"));
  #ifdef FEAT_EVAL
*** ../vim-8.2.2298/src/vim9compile.c   2021-01-04 12:41:49.507891351 +0100
--- src/vim9compile.c   2021-01-04 15:42:44.809095238 +0100
***************
*** 7797,7802 ****
--- 7797,7809 ----
                   : (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local,
                                                                        &cctx);
  
+       if (p == NULL)
+       {
+           if (cctx.ctx_skip != SKIP_YES)
+               emsg(_(e_ambiguous_use_of_user_defined_command));
+           goto erret;
+       }
+ 
        if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
        {
            if (cctx.ctx_skip == SKIP_YES)
*** ../vim-8.2.2298/src/testdir/test_vim9_cmd.vim       2021-01-02 
19:44:50.702794031 +0100
--- src/testdir/test_vim9_cmd.vim       2021-01-04 16:11:54.726874382 +0100
***************
*** 771,776 ****
--- 771,794 ----
    CheckScriptSuccess(lines)
  enddef
  
+ def Test_user_command_comment()
+   command -nargs=1 Comd echom <q-args>
+ 
+   var lines =<< trim END
+     vim9script
+     Comd # comment
+   END
+   CheckScriptSuccess(lines)
+ 
+   lines =<< trim END
+     vim9script
+     Comd# comment
+   END
+   CheckScriptFailure(lines, 'E1144:')
+ 
+   delcommand Comd
+ enddef
+ 
  def Test_star_command()
    var lines =<< trim END
      vim9script
***************
*** 798,809 ****
  enddef
  
  def Test_ambiguous_user_cmd()
    var lines =<< trim END
-       com Cmd1 eval 0
-       com Cmd2 eval 0
        Cmd
    END
!   CheckScriptFailure(lines, 'E464:')
  enddef
  
  def Test_command_not_recognized()
--- 816,829 ----
  enddef
  
  def Test_ambiguous_user_cmd()
+   command Cmd1 eval 0
+   command Cmd2 eval 0
    var lines =<< trim END
        Cmd
    END
!   CheckDefAndScriptFailure(lines, 'E464:', 1)
!   delcommand Cmd1
!   delcommand Cmd2
  enddef
  
  def Test_command_not_recognized()
*** ../vim-8.2.2298/src/version.c       2021-01-04 14:09:40.053795023 +0100
--- src/version.c       2021-01-04 15:27:30.544758787 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2299,
  /**/

-- 
I AM THANKFUL...
...for the taxes that I pay because it means that I am employed.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202101041552.104FqqhM2476713%40masaka.moolenaar.net.

Raspunde prin e-mail lui