]> granicus.if.org Git - vim/commitdiff
patch 8.1.0511: ml_get error when calling a function with a range v8.1.0511
authorBram Moolenaar <Bram@vim.org>
Sun, 4 Nov 2018 22:39:38 +0000 (23:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Nov 2018 22:39:38 +0000 (23:39 +0100)
Problem:    ml_get error when calling a function with a range.
Solution:   Don't position the cursor after the last line.

src/testdir/test_functions.vim
src/userfunc.c
src/version.c

index e59cdf82a39efe039f35c550e43e0b85f0af7006..ac8a27f75ad28ffc071ab6e084a20e659a75a18a 100644 (file)
@@ -1119,3 +1119,22 @@ func Test_func_sandbox()
   call assert_fails('call Fsandbox()', 'E48:')
   delfunc Fsandbox
 endfunc
+
+func EditAnotherFile()
+  let word = expand('<cword>')
+  edit Xfuncrange2
+endfunc
+
+func Test_func_range_with_edit()
+  " Define a function that edits another buffer, then call it with a range that
+  " is invalid in that buffer.
+  call writefile(['just one line'], 'Xfuncrange2')
+  new
+  call setline(1, range(10))
+  write Xfuncrange1
+  call assert_fails('5,8call EditAnotherFile()', 'E16:')
+
+  call delete('Xfuncrange1')
+  call delete('Xfuncrange2')
+  bwipe!
+endfunc
index 7c3b7f673ac5de6614e2ab43c04b42721889ca92..f79e7f17553b35cb7bcf9f500af0cb35522317ed 100644 (file)
@@ -3149,6 +3149,13 @@ ex_call(exarg_T *eap)
     {
        if (!eap->skip && eap->addr_count > 0)
        {
+           if (lnum > curbuf->b_ml.ml_line_count)
+           {
+               // If the function deleted lines or switched to another buffer
+               // the line number may become invalid.
+               EMSG(_(e_invrange));
+               break;
+           }
            curwin->w_cursor.lnum = lnum;
            curwin->w_cursor.col = 0;
 #ifdef FEAT_VIRTUALEDIT
index a5b6d877b86a7143351c8ce7932c874c1957a69f..8440ce94015758b526d39acc07c0181bf02c612b 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    511,
 /**/
     510,
 /**/