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;
}
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)
{
#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)
--- /dev/null
+" 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
+