]> granicus.if.org Git - vim/commitdiff
patch 8.0.0962: crash with virtualedit and joining lines v8.0.0962
authorBram Moolenaar <Bram@vim.org>
Sat, 19 Aug 2017 13:05:32 +0000 (15:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 19 Aug 2017 13:05:32 +0000 (15:05 +0200)
Problem:    Crash with virtualedit and joining lines. (Joshua T Corbin, Neovim
            #6726)
Solution:   When using a mark check that coladd is valid.

src/Makefile
src/misc2.c
src/normal.c
src/testdir/test_alot.vim
src/testdir/test_virtualedit.vim [new file with mode: 0644]
src/version.c

index de4b2406412a2c6efc172c6fab78181ea6ae7e5c..1f252f0565fde7fa22496b1e3b47043da2ded418 100644 (file)
@@ -2274,6 +2274,7 @@ test_arglist \
        test_utf8_comparisons \
        test_viminfo \
        test_vimscript \
+       test_virtualedit \
        test_visual \
        test_window_cmd \
        test_window_id \
index 541069e54b6ce6bb9cab7164889a743ad74547b5..17fa424bc89435978fe460c96c49c359c7e18d01 100644 (file)
@@ -605,7 +605,18 @@ check_cursor_col_win(win_T *win)
     else if (ve_flags == VE_ALL)
     {
        if (oldcoladd > win->w_cursor.col)
+       {
            win->w_cursor.coladd = oldcoladd - win->w_cursor.col;
+           if (win->w_cursor.col < len && win->w_cursor.coladd > 0)
+           {
+               int cs, ce;
+
+               /* check that coladd is not more than the char width */
+               getvcol(win, &win->w_cursor, &cs, NULL, &ce);
+               if (win->w_cursor.coladd > ce - cs)
+                   win->w_cursor.coladd = ce - cs;
+           }
+       }
        else
            /* avoid weird number when there is a miscalculation or overflow */
            win->w_cursor.coladd = 0;
index c543635ef4e5f91dc93034ea2fd184202eef5e2d..f08f52f9fe2e61bfe9487e0e75b17b3a14319729 100644 (file)
@@ -1571,7 +1571,12 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
 
            oap->start = VIsual;
            if (VIsual_mode == 'V')
+           {
                oap->start.col = 0;
+# ifdef FEAT_VIRTUALEDIT
+               oap->start.coladd = 0;
+# endif
+           }
        }
 
        /*
@@ -7580,6 +7585,7 @@ nv_gomark(cmdarg_T *cap)
     if (!virtual_active())
        curwin->w_cursor.coladd = 0;
 #endif
+    check_cursor_col();
 #ifdef FEAT_FOLDING
     if (cap->oap->op_type == OP_NOP
            && pos != NULL
index 8e245ed20d2bf37b6700c91ca268a9c16121121d..e83256a4d327453cba722a214e5a54f4765b6854 100644 (file)
@@ -55,4 +55,5 @@ source test_taglist.vim
 source test_timers.vim
 source test_true_false.vim
 source test_unlet.vim
+source test_virtualedit.vim
 source test_window_cmd.vim
diff --git a/src/testdir/test_virtualedit.vim b/src/testdir/test_virtualedit.vim
new file mode 100644 (file)
index 0000000..da143c5
--- /dev/null
@@ -0,0 +1,31 @@
+" Tests for 'virtualedit'.
+
+func Test_yank_move_change()
+  split
+  call setline(1, [
+       \ "func foo() error {",
+       \ "\tif n, err := bar();",
+       \ "\terr != nil {",
+       \ "\t\treturn err",
+       \ "\t}",
+       \ "\tn = n * n",
+       \ ])
+  set virtualedit=all
+  set ts=4
+  function! MoveSelectionDown(count) abort
+    normal! m`
+    silent! exe "'<,'>move'>+".a:count
+    norm! ``
+  endfunction
+
+  xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR>
+  2
+  normal 2gg
+  normal J
+  normal jVj
+  normal ]e
+  normal ce
+  bwipe!
+  set virtualedit=
+  set ts=8
+endfunc
index a25bbadcb53e6b5c05b05c5cddcf21a61e8293b6..1ba0073b02aaaf03f1b1d7e70d8f281073c2a33e 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    962,
 /**/
     961,
 /**/