Skip to content

Commit e99f068

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0062: Internal error when :luado/perldo/pydo etc delete lines
Problem: Internal error when :luado/perldo/pydo etc delete lines Solution: Test that the line is still valid line number (zeertzjq) closes: #13931 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e6d8b46 commit e99f068

12 files changed

Lines changed: 111 additions & 13 deletions

src/if_lua.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2692,9 +2692,12 @@ ex_luado(exarg_T *eap)
26922692
luaV_emsg(L);
26932693
break;
26942694
}
2695+
26952696
// Catch the command switching to another buffer.
2696-
if (curbuf != was_curbuf)
2697+
// Check the line number, the command may have deleted lines.
2698+
if (curbuf != was_curbuf || l > curbuf->b_ml.ml_line_count)
26972699
break;
2700+
26982701
if (lua_isstring(L, -1)) // update line?
26992702
{
27002703
#ifdef HAVE_SANDBOX

src/if_perl.xs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ ex_perldo(exarg_T *eap)
13681368
PUSHMARK(sp);
13691369
perl_call_pv("VIM::perldo", G_SCALAR | G_EVAL);
13701370
str = SvPV(GvSV(PL_errgv), length);
1371-
if (length || curbuf != was_curbuf)
1371+
if (length || curbuf != was_curbuf || i > curbuf->b_ml.ml_line_count)
13721372
break;
13731373
SPAGAIN;
13741374
if (SvTRUEx(POPs))

src/if_py_both.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6136,7 +6136,8 @@ run_do(const char *cmd, void *arg UNUSED
61366136
goto err;
61376137

61386138
// Check that the command didn't switch to another buffer.
6139-
if (curbuf != was_curbuf)
6139+
// Check the line number, the command my have deleted lines.
6140+
if (curbuf != was_curbuf || lnum > curbuf->b_ml.ml_line_count)
61406141
{
61416142
Py_XDECREF(ret);
61426143
goto err;

src/if_ruby.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ ex_rubydo(exarg_T *eap)
885885
error_print(state);
886886
break;
887887
}
888-
if (was_curbuf != curbuf)
888+
if (was_curbuf != curbuf || i > curbuf->b_ml.ml_line_count)
889889
break;
890890
line = rb_lastline_get();
891891
if (!NIL_P(line))

src/if_tcl.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,8 @@ ex_tcldo(exarg_T *eap)
20122012
#if (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 5) || TCL_MAJOR_VERSION > 8
20132013
|| Tcl_LimitExceeded(tclinfo.interp)
20142014
#endif
2015-
|| curbuf != was_curbuf)
2015+
|| curbuf != was_curbuf
2016+
|| (linenr_T)rs > curbuf->b_ml.ml_line_count)
20162017
break;
20172018
line = (char *)Tcl_GetVar(tclinfo.interp, var_line, 0);
20182019
if (line)

src/testdir/test_lua.vim

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,37 @@ func TearDown()
2828
endfunc
2929

3030
" Check that switching to another buffer does not trigger ml_get error.
31-
func Test_lua_command_new_no_ml_get_error()
31+
func Test_lua_luado_change_buffer()
3232
new
33+
3334
let wincount = winnr('$')
3435
call setline(1, ['one', 'two', 'three'])
3536
luado vim.command("new")
3637
call assert_equal(wincount + 1, winnr('$'))
38+
3739
%bwipe!
3840
endfunc
3941

40-
" Test vim.command()
41-
func Test_lua_command()
42+
" Check that :luado deleting lines does not trigger ml_get error.
43+
func Test_lua_luado_delete_lines()
4244
new
45+
46+
call setline(1, ['one', 'two', 'three'])
47+
luado vim.command("%d_")
48+
call assert_equal([''], getline(1, '$'))
49+
4350
call setline(1, ['one', 'two', 'three'])
4451
luado vim.command("1,2d_")
4552
call assert_equal(['three'], getline(1, '$'))
53+
54+
call setline(1, ['one', 'two', 'three'])
55+
luado vim.command("2,3d_"); return "REPLACED"
56+
call assert_equal(['REPLACED'], getline(1, '$'))
57+
58+
call setline(1, ['one', 'two', 'three'])
59+
2,3luado vim.command("1,2d_"); return "REPLACED"
60+
call assert_equal(['three'], getline(1, '$'))
61+
4662
bwipe!
4763
endfunc
4864

src/testdir/test_perl.vim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,25 @@ func Test_perldo()
211211
call assert_false(search('\Cperl'))
212212
bw!
213213

214-
" Check deleting lines does not trigger ml_get error.
215214
new
215+
216+
" Check deleting lines does not trigger ml_get error.
216217
call setline(1, ['one', 'two', 'three'])
217218
perldo VIM::DoCommand("%d_")
219+
call assert_equal([''], getline(1, '$'))
220+
221+
call setline(1, ['one', 'two', 'three'])
222+
perldo VIM::DoCommand("1,2d_")
223+
call assert_equal(['three'], getline(1, '$'))
224+
225+
call setline(1, ['one', 'two', 'three'])
226+
perldo VIM::DoCommand("2,3d_"); $_ = "REPLACED"
227+
call assert_equal(['REPLACED'], getline(1, '$'))
228+
229+
call setline(1, ['one', 'two', 'three'])
230+
2,3perldo VIM::DoCommand("1,2d_"); $_ = "REPLACED"
231+
call assert_equal(['three'], getline(1, '$'))
232+
218233
bwipe!
219234

220235
" Check a Perl expression which gives an error.

src/testdir/test_python2.vim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,25 @@ func Test_AAA_python_setup()
5656
endfunc
5757

5858
func Test_pydo()
59-
" Check deleting lines does not trigger an ml_get error.
6059
new
60+
61+
" Check deleting lines does not trigger an ml_get error.
6162
call setline(1, ['one', 'two', 'three'])
6263
pydo vim.command("%d_")
64+
call assert_equal([''], getline(1, '$'))
65+
66+
call setline(1, ['one', 'two', 'three'])
67+
pydo vim.command("1,2d_")
68+
call assert_equal(['three'], getline(1, '$'))
69+
70+
call setline(1, ['one', 'two', 'three'])
71+
pydo vim.command("2,3d_"); return "REPLACED"
72+
call assert_equal(['REPLACED'], getline(1, '$'))
73+
74+
call setline(1, ['one', 'two', 'three'])
75+
2,3pydo vim.command("1,2d_"); return "REPLACED"
76+
call assert_equal(['three'], getline(1, '$'))
77+
6378
bwipe!
6479

6580
" Check switching to another buffer does not trigger an ml_get error.

src/testdir/test_python3.vim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,25 @@ func Test_AAA_python3_setup()
8888
endfunc
8989

9090
func Test_py3do()
91-
" Check deleting lines does not trigger an ml_get error.
9291
new
92+
93+
" Check deleting lines does not trigger an ml_get error.
9394
call setline(1, ['one', 'two', 'three'])
9495
py3do vim.command("%d_")
96+
call assert_equal([''], getline(1, '$'))
97+
98+
call setline(1, ['one', 'two', 'three'])
99+
py3do vim.command("1,2d_")
100+
call assert_equal(['three'], getline(1, '$'))
101+
102+
call setline(1, ['one', 'two', 'three'])
103+
py3do vim.command("2,3d_"); return "REPLACED"
104+
call assert_equal(['REPLACED'], getline(1, '$'))
105+
106+
call setline(1, ['one', 'two', 'three'])
107+
2,3py3do vim.command("1,2d_"); return "REPLACED"
108+
call assert_equal(['three'], getline(1, '$'))
109+
95110
bwipe!
96111

97112
" Check switching to another buffer does not trigger an ml_get error.

src/testdir/test_ruby.vim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ func Test_ruby_change_buffer()
1111
endfunc
1212

1313
func Test_rubydo()
14-
" Check deleting lines does not trigger ml_get error.
1514
new
15+
16+
" Check deleting lines does not trigger ml_get error.
1617
call setline(1, ['one', 'two', 'three'])
1718
rubydo Vim.command("%d_")
19+
call assert_equal(['one'], getline(1, '$'))
20+
21+
call setline(1, ['one', 'two', 'three'])
22+
rubydo Vim.command("1,2d_")
23+
call assert_equal(['one'], getline(1, '$'))
24+
25+
call setline(1, ['one', 'two', 'three'])
26+
rubydo Vim.command("2,3d_"); $_ = "REPLACED"
27+
call assert_equal(['REPLACED'], getline(1, '$'))
28+
29+
call setline(1, ['one', 'two', 'three'])
30+
2,3rubydo Vim.command("1,2d_"); $_ = "REPLACED"
31+
call assert_equal(['three'], getline(1, '$'))
32+
1833
bwipe!
1934

2035
" Check switching to another buffer does not trigger ml_get error.

0 commit comments

Comments
 (0)