]> granicus.if.org Git - vim/commitdiff
patch 8.2.4009: reading one byte beyond the end of the line v8.2.4009
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Jan 2022 16:50:40 +0000 (16:50 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Jan 2022 16:50:40 +0000 (16:50 +0000)
Problem:    Reading one byte beyond the end of the line.
Solution:   Check for NUL byte first.

src/ex_docmd.c
src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index 41cbd3090f86ab7b3654191fb5e6b57da263ad14..1f15bc8544d77b1d76a0779f6db802580d11dd1e 100644 (file)
@@ -3632,7 +3632,8 @@ find_ex_command(
        }
 
        // Check for "++nr" and "--nr".
-       if (p == eap->cmd && p[0] == p[1] && (*p == '+' || *p == '-'))
+       if (p == eap->cmd && p[0] != NUL && p[0] == p[1]
+                                                  && (*p == '+' || *p == '-'))
        {
            eap->cmdidx = *p == '+' ? CMD_increment : CMD_decrement;
            return eap->cmd + 2;
index 0ec1700dc621e6a65daafb389cd6c1c672dfdb18..025edd5dafa332152a854b45c2a597b8484d155f 100644 (file)
@@ -3537,6 +3537,17 @@ def Test_numbered_function_reference()
   unlet g:mydict
 enddef
 
+def Test_go_beyond_end_of_cmd()
+  # this was reading the byte after the end of the line
+  var lines =<< trim END
+    def F()
+      cal
+    enddef
+    defcompile
+  END
+  CheckScriptFailure(lines, 'E476:')
+enddef
+
 if has('python3')
   def Test_python3_heredoc()
     py3 << trim EOF
index 48a1c9820e1f9cf980814e61160a55e91ef03a78..6b7a915c4fc195f587966c024506484c5e88ef8b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4009,
 /**/
     4008,
 /**/
index cccf02c2c52cb57d139ad4a57804cbc7f01ab32d..f1a6a031163dd360a273cb4b92eaefbd2273a394 100644 (file)
@@ -2781,7 +2781,8 @@ compile_def_function(
        cmd = ea.cmd;
        if ((*cmd != '$' || starts_with_colon)
                && (starts_with_colon || !(*cmd == '\''
-                      || (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-')))))
+                      || (cmd[0] != NUL && cmd[0] == cmd[1]
+                                           && (*cmd == '+' || *cmd == '-')))))
        {
            ea.cmd = skip_range(ea.cmd, TRUE, NULL);
            if (ea.cmd > cmd)