summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-03-06 12:10:48 +0100
committerBram Moolenaar <Bram@vim.org>2018-03-06 12:10:48 +0100
commit63e82db6fc910b2d8f1cd018894e50e8b4448155 (patch)
treeecd9a84d5303a6712e599ba7f9b6ba0bd679804c
parent987723e084660290270b3c3d943eb13bd828d5da (diff)
patch 8.0.1575: crash when using virtual replacev8.0.1575
Problem: Crash when using virtual replace. Solution: Adjust orig_line_count. Add more tests. (Christian Brabandt)
-rw-r--r--src/edit.c10
-rw-r--r--src/testdir/test_visual.vim59
-rw-r--r--src/version.c2
3 files changed, 69 insertions, 2 deletions
diff --git a/src/edit.c b/src/edit.c
index 423ccea449..21941cb3d0 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -8907,7 +8907,17 @@ ins_del(void)
|| do_join(2, FALSE, TRUE, FALSE, FALSE) == FAIL)
vim_beep(BO_BS);
else
+ {
curwin->w_cursor.col = temp;
+#ifdef FEAT_VREPLACE
+ /* Adjust orig_line_count in case more lines have been deleted than
+ * have been added. That makes sure, that open_line() later
+ * can access all buffer lines correctly */
+ if (State & VREPLACE_FLAG &&
+ orig_line_count > curbuf->b_ml.ml_line_count)
+ orig_line_count = curbuf->b_ml.ml_line_count;
+#endif
+ }
}
else if (del_char(FALSE) == FAIL) /* delete char under cursor */
vim_beep(BO_BS);
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
index 4287a9e491..9d0458cd2d 100644
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -70,13 +70,13 @@ func TriggerTheProblem()
exe "normal \<Esc>"
catch /^Vim\%((\a\+)\)\=:E315/
echom 'Snap! E315 error!'
- let g:msg='Snap! E315 error!'
+ let g:msg = 'Snap! E315 error!'
endtry
endfunc
func Test_visual_mode_reset()
enew
- let g:msg="Everything's fine."
+ let g:msg = "Everything's fine."
enew
setl buftype=nofile
call append(line('$'), 'Delete this line.')
@@ -186,4 +186,59 @@ func Test_virtual_replace()
call assert_equal(['AB......CDEFGHI.Jkl',
\ 'AB IJKLMNO QRst'], getline(12, 13))
enew!
+ set noai bs&vim t_kD&vim t_kb&vim
+endfunc
+
+" Test Virtual replace mode.
+func Test_virtual_replace2()
+ enew!
+ set bs=2
+ exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz"
+ call cursor(1,1)
+ " Test 1: Test that del deletes the newline
+ exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR"
+ call assert_equal(['0 1',
+ \ 'A',
+ \ 'BCDEFGHIJ',
+ \ ' KL',
+ \ 'MNO',
+ \ 'PQR',
+ \ ], getline(1, 6))
+ " Test 2:
+ " a newline is not deleted, if no newline has been added in virtual replace mode
+ %d_
+ call setline(1, ['abcd', 'efgh', 'ijkl'])
+ call cursor(2,1)
+ exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>"
+ call assert_equal(['abcd',
+ \ '123h',
+ \ 'ijkl'], getline(1, '$'))
+ " Test 3:
+ " a newline is deleted, if a newline has been inserted before in virtual replace mode
+ %d_
+ call setline(1, ['abcd', 'efgh', 'ijkl'])
+ call cursor(2,1)
+ exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>"
+ call assert_equal(['abcd',
+ \ '1234',
+ \ 'ijkl'], getline(1, '$'))
+ " Test 4:
+ " delete add a newline, delete it, add it again and check undo
+ %d_
+ call setline(1, ['abcd', 'efgh', 'ijkl'])
+ call cursor(2,1)
+ " break undo sequence explicitly
+ let &ul = &ul
+ exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>"
+ let &ul = &ul
+ call assert_equal(['abcd',
+ \ '123456',
+ \ ''], getline(1, '$'))
+ norm! u
+ call assert_equal(['abcd',
+ \ 'efgh',
+ \ 'ijkl'], getline(1, '$'))
+ " clean up
+ %d_
+ set bs&vim
endfunc
diff --git a/src/version.c b/src/version.c
index 3cf2550189..c47cf6bb1e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -767,6 +767,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1575,
+/**/
1574,
/**/
1573,