Skip to content

Commit 63e82db

Browse files
committed
patch 8.0.1575: crash when using virtual replace
Problem: Crash when using virtual replace. Solution: Adjust orig_line_count. Add more tests. (Christian Brabandt)
1 parent 987723e commit 63e82db

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

src/edit.c

+10
Original file line numberDiff line numberDiff line change
@@ -8907,7 +8907,17 @@ ins_del(void)
89078907
|| do_join(2, FALSE, TRUE, FALSE, FALSE) == FAIL)
89088908
vim_beep(BO_BS);
89098909
else
8910+
{
89108911
curwin->w_cursor.col = temp;
8912+
#ifdef FEAT_VREPLACE
8913+
/* Adjust orig_line_count in case more lines have been deleted than
8914+
* have been added. That makes sure, that open_line() later
8915+
* can access all buffer lines correctly */
8916+
if (State & VREPLACE_FLAG &&
8917+
orig_line_count > curbuf->b_ml.ml_line_count)
8918+
orig_line_count = curbuf->b_ml.ml_line_count;
8919+
#endif
8920+
}
89118921
}
89128922
else if (del_char(FALSE) == FAIL) /* delete char under cursor */
89138923
vim_beep(BO_BS);

src/testdir/test_visual.vim

+57-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ func TriggerTheProblem()
7070
exe "normal \<Esc>"
7171
catch /^Vim\%((\a\+)\)\=:E315/
7272
echom 'Snap! E315 error!'
73-
let g:msg='Snap! E315 error!'
73+
let g:msg = 'Snap! E315 error!'
7474
endtry
7575
endfunc
7676

7777
func Test_visual_mode_reset()
7878
enew
79-
let g:msg="Everything's fine."
79+
let g:msg = "Everything's fine."
8080
enew
8181
setl buftype=nofile
8282
call append(line('$'), 'Delete this line.')
@@ -186,4 +186,59 @@ func Test_virtual_replace()
186186
call assert_equal(['AB......CDEFGHI.Jkl',
187187
\ 'AB IJKLMNO QRst'], getline(12, 13))
188188
enew!
189+
set noai bs&vim t_kD&vim t_kb&vim
190+
endfunc
191+
192+
" Test Virtual replace mode.
193+
func Test_virtual_replace2()
194+
enew!
195+
set bs=2
196+
exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz"
197+
call cursor(1,1)
198+
" Test 1: Test that del deletes the newline
199+
exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR"
200+
call assert_equal(['0 1',
201+
\ 'A',
202+
\ 'BCDEFGHIJ',
203+
\ ' KL',
204+
\ 'MNO',
205+
\ 'PQR',
206+
\ ], getline(1, 6))
207+
" Test 2:
208+
" a newline is not deleted, if no newline has been added in virtual replace mode
209+
%d_
210+
call setline(1, ['abcd', 'efgh', 'ijkl'])
211+
call cursor(2,1)
212+
exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>"
213+
call assert_equal(['abcd',
214+
\ '123h',
215+
\ 'ijkl'], getline(1, '$'))
216+
" Test 3:
217+
" a newline is deleted, if a newline has been inserted before in virtual replace mode
218+
%d_
219+
call setline(1, ['abcd', 'efgh', 'ijkl'])
220+
call cursor(2,1)
221+
exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>"
222+
call assert_equal(['abcd',
223+
\ '1234',
224+
\ 'ijkl'], getline(1, '$'))
225+
" Test 4:
226+
" delete add a newline, delete it, add it again and check undo
227+
%d_
228+
call setline(1, ['abcd', 'efgh', 'ijkl'])
229+
call cursor(2,1)
230+
" break undo sequence explicitly
231+
let &ul = &ul
232+
exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>"
233+
let &ul = &ul
234+
call assert_equal(['abcd',
235+
\ '123456',
236+
\ ''], getline(1, '$'))
237+
norm! u
238+
call assert_equal(['abcd',
239+
\ 'efgh',
240+
\ 'ijkl'], getline(1, '$'))
241+
" clean up
242+
%d_
243+
set bs&vim
189244
endfunc

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ static char *(features[]) =
766766

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1575,
769771
/**/
770772
1574,
771773
/**/

0 commit comments

Comments
 (0)