Skip to content

Commit a4c906a

Browse files
committed
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 #1421) Solution: Check the buffer and line every time.
1 parent c593fee commit a4c906a

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,6 +2198,7 @@ test_arglist \
21982198
test_tabpage \
21992199
test_tagcase \
22002200
test_tagjump \
2201+
test_tcl \
22012202
test_textobjects \
22022203
test_timers \
22032204
test_true_false \

src/if_tcl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,7 @@ ex_tcldo(exarg_T *eap)
19581958
char var_line[VARNAME_SIZE];
19591959
linenr_T first_line = 0;
19601960
linenr_T last_line = 0;
1961+
buf_T *was_curbuf = curbuf;
19611962

19621963
rs = eap->line1;
19631964
re = eap->line2;
@@ -1979,6 +1980,8 @@ ex_tcldo(exarg_T *eap)
19791980
}
19801981
while (err == TCL_OK && rs <= re)
19811982
{
1983+
if ((linenr_T)rs > curbuf->b_ml.ml_line_count)
1984+
break;
19821985
line = (char *)ml_get_buf(curbuf, (linenr_T)rs, FALSE);
19831986
if (!line)
19841987
{
@@ -1994,7 +1997,7 @@ ex_tcldo(exarg_T *eap)
19941997
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8
19951998
|| Tcl_LimitExceeded(tclinfo.interp)
19961999
#endif
1997-
)
2000+
|| curbuf != was_curbuf)
19982001
break;
19992002
line = (char *)Tcl_GetVar(tclinfo.interp, var_line, 0);
20002003
if (line)

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ NEW_TESTS = test_arglist.res \
193193
test_substitute.res \
194194
test_syntax.res \
195195
test_system.res \
196+
test_tcl.res \
196197
test_textobjects.res \
197198
test_undo.res \
198199
test_usercommands.res \

src/testdir/test_tcl.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
" Tests for the Tcl interface.
2+
3+
if !has('tcl')
4+
finish
5+
end
6+
7+
function Test_tcldo()
8+
" Check deleting lines does not trigger ml_get error.
9+
new
10+
call setline(1, ['one', 'two', 'three'])
11+
tcldo ::vim::command %d_
12+
bwipe!
13+
14+
" Check switching to another buffer does not trigger ml_get error.
15+
new
16+
let wincount = winnr('$')
17+
call setline(1, ['one', 'two', 'three'])
18+
tcldo ::vim::command new
19+
call assert_equal(wincount + 1, winnr('$'))
20+
bwipe!
21+
bwipe!
22+
endfunc
23+

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
271,
767769
/**/
768770
270,
769771
/**/

0 commit comments

Comments
 (0)