changeset 10763:ae0bbbbe2a38 v8.0.0271

patch 8.0.0271: may get ml_get error when :tcldo deletes lines commit https://github.com/vim/vim/commit/a4c906a4a111cbe59cf5f1e8354a36ba83e0a444 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 29 23:26:37 2017 +0100 patch 8.0.0271: may get ml_get error when :tcldo deletes lines Problem: May get ml_get error when :tcldo deletes lines or switches to another buffer. (Nikolai Pavlov, closes https://github.com/vim/vim/issues/1421) Solution: Check the buffer and line every time.
author Christian Brabandt <cb@256bit.org>
date Sun, 29 Jan 2017 23:30:04 +0100
parents 7f61aa32d954
children 3e8acc7378c4
files src/Makefile src/if_tcl.c src/testdir/Make_all.mak src/testdir/test_tcl.vim src/version.c
diffstat 5 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile
+++ b/src/Makefile
@@ -2198,6 +2198,7 @@ test_arglist \
 	test_tabpage \
 	test_tagcase \
 	test_tagjump \
+	test_tcl \
 	test_textobjects \
 	test_timers \
 	test_true_false \
--- a/src/if_tcl.c
+++ b/src/if_tcl.c
@@ -1958,6 +1958,7 @@ ex_tcldo(exarg_T *eap)
     char	var_line[VARNAME_SIZE];
     linenr_T	first_line = 0;
     linenr_T	last_line = 0;
+    buf_T	*was_curbuf = curbuf;
 
     rs = eap->line1;
     re = eap->line2;
@@ -1979,6 +1980,8 @@ ex_tcldo(exarg_T *eap)
     }
     while (err == TCL_OK  &&  rs <= re)
     {
+	if ((linenr_T)rs > curbuf->b_ml.ml_line_count)
+	    break;
 	line = (char *)ml_get_buf(curbuf, (linenr_T)rs, FALSE);
 	if (!line)
 	{
@@ -1994,7 +1997,7 @@ ex_tcldo(exarg_T *eap)
 #if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8
 	    || Tcl_LimitExceeded(tclinfo.interp)
 #endif
-	   )
+	    || curbuf != was_curbuf)
 	    break;
 	line = (char *)Tcl_GetVar(tclinfo.interp, var_line, 0);
 	if (line)
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -193,6 +193,7 @@ NEW_TESTS = test_arglist.res \
 	    test_substitute.res \
 	    test_syntax.res \
 	    test_system.res \
+	    test_tcl.res \
 	    test_textobjects.res \
 	    test_undo.res \
 	    test_usercommands.res \
new file mode 100644
--- /dev/null
+++ b/src/testdir/test_tcl.vim
@@ -0,0 +1,23 @@
+" Tests for the Tcl interface.
+
+if !has('tcl')
+  finish
+end
+
+function Test_tcldo()
+  " Check deleting lines does not trigger ml_get error.
+  new
+  call setline(1, ['one', 'two', 'three'])
+  tcldo ::vim::command %d_
+  bwipe!
+
+  " Check switching to another buffer does not trigger ml_get error.
+  new
+  let wincount = winnr('$')
+  call setline(1, ['one', 'two', 'three'])
+  tcldo ::vim::command new
+  call assert_equal(wincount + 1, winnr('$'))
+  bwipe!
+  bwipe!
+endfunc
+
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    271,
+/**/
     270,
 /**/
     269,