]> granicus.if.org Git - vim/commitdiff
patch 8.0.0271: may get ml_get error when :tcldo deletes lines v8.0.0271
authorBram Moolenaar <Bram@vim.org>
Sun, 29 Jan 2017 22:26:37 +0000 (23:26 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 29 Jan 2017 22:26:37 +0000 (23:26 +0100)
Problem:    May get ml_get error when :tcldo deletes lines or switches to
            another buffer. (Nikolai Pavlov, closes #1421)
Solution:   Check the buffer and line every time.

src/Makefile
src/if_tcl.c
src/testdir/Make_all.mak
src/testdir/test_tcl.vim [new file with mode: 0644]
src/version.c

index f26a1bf33c043b6754237f4232c3de96d0e742ef..922a09bfd5e70c2eabbc9dd12f27dd37fa9803cb 100644 (file)
@@ -2198,6 +2198,7 @@ test_arglist \
        test_tabpage \
        test_tagcase \
        test_tagjump \
+       test_tcl \
        test_textobjects \
        test_timers \
        test_true_false \
index 1e856c7af437b13b6b198bccfe5b3d45a7d7accc..9b47f1b04544c6b7591e80f48b09897f9d35b63c 100644 (file)
@@ -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)
index bb646ee1b01b4c773f363c97d535aa197ad2545e..c42aae63bd215f94616bb2c51aa3cdbffe5eac59 100644 (file)
@@ -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 \
diff --git a/src/testdir/test_tcl.vim b/src/testdir/test_tcl.vim
new file mode 100644 (file)
index 0000000..ac772cc
--- /dev/null
@@ -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
+
index 44e5b6fb576dc13d519a69a70472d4abcd0b8c0e..9474c5ea8e2cf142e86ad445b467e1d25790365a 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    271,
 /**/
     270,
 /**/