Skip to content

Commit 9e353b5

Browse files
committed
patch 8.1.0511: ml_get error when calling a function with a range
Problem: ml_get error when calling a function with a range. Solution: Don't position the cursor after the last line.
1 parent ba3ff53 commit 9e353b5

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/testdir/test_functions.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,3 +1119,22 @@ func Test_func_sandbox()
11191119
call assert_fails('call Fsandbox()', 'E48:')
11201120
delfunc Fsandbox
11211121
endfunc
1122+
1123+
func EditAnotherFile()
1124+
let word = expand('<cword>')
1125+
edit Xfuncrange2
1126+
endfunc
1127+
1128+
func Test_func_range_with_edit()
1129+
" Define a function that edits another buffer, then call it with a range that
1130+
" is invalid in that buffer.
1131+
call writefile(['just one line'], 'Xfuncrange2')
1132+
new
1133+
call setline(1, range(10))
1134+
write Xfuncrange1
1135+
call assert_fails('5,8call EditAnotherFile()', 'E16:')
1136+
1137+
call delete('Xfuncrange1')
1138+
call delete('Xfuncrange2')
1139+
bwipe!
1140+
endfunc

src/userfunc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,13 @@ ex_call(exarg_T *eap)
31493149
{
31503150
if (!eap->skip && eap->addr_count > 0)
31513151
{
3152+
if (lnum > curbuf->b_ml.ml_line_count)
3153+
{
3154+
// If the function deleted lines or switched to another buffer
3155+
// the line number may become invalid.
3156+
EMSG(_(e_invrange));
3157+
break;
3158+
}
31523159
curwin->w_cursor.lnum = lnum;
31533160
curwin->w_cursor.col = 0;
31543161
#ifdef FEAT_VIRTUALEDIT

src/version.c

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

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
511,
795797
/**/
796798
510,
797799
/**/

0 commit comments

Comments
 (0)