diff options
author | Christian Clason <c.clason@uni-graz.at> | 2022-01-26 21:33:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 21:33:53 +0100 |
commit | 17e2938b100070d91bd956c8734760ca16f6d3f2 (patch) | |
tree | 8c031c6f12c3b30bc18ea6dc62b41b2c281e0c69 | |
parent | 20482a2b83b9ea56ce226239ebb6c0fe7819c6f1 (diff) | |
parent | dda1c8edda86a50d802f777e5ba2379f7ccd6ae8 (diff) | |
download | rneovim-17e2938b100070d91bd956c8734760ca16f6d3f2.tar.gz rneovim-17e2938b100070d91bd956c8734760ca16f6d3f2.tar.bz2 rneovim-17e2938b100070d91bd956c8734760ca16f6d3f2.zip |
Merge pull request #17132 from zeertzjq/vim-8.2.3611
vim-patch:8.2.{3494,3611,3613}: two Visual mode crash fixes
-rw-r--r-- | src/nvim/file_search.c | 6 | ||||
-rw-r--r-- | src/nvim/normal.c | 16 | ||||
-rw-r--r-- | src/nvim/path.c | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test_visual.vim | 30 |
4 files changed, 47 insertions, 9 deletions
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index b2cd5c510b..b4becb3066 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -1433,7 +1433,11 @@ char_u *find_file_in_path_option(char_u *ptr, size_t len, int options, int first rel_fname = NULL; } - if (first == TRUE) { + if (first == true) { + if (len == 0) { + return NULL; + } + // copy file name into NameBuff, expanding environment variables save_char = ptr[len]; ptr[len] = NUL; diff --git a/src/nvim/normal.c b/src/nvim/normal.c index c3b7e81d17..63311160a7 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -4472,8 +4472,13 @@ bool get_visual_text(cmdarg_T *cap, char_u **pp, size_t *lenp) *pp = ml_get_pos(&VIsual); *lenp = (size_t)curwin->w_cursor.col - (size_t)VIsual.col + 1; } - // Correct the length to include the whole last character. - *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1); + if (**pp == NUL) { + *lenp = 0; + } + if (*lenp > 0) { + // Correct the length to include all bytes of the last character. + *lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1); + } } reset_VIsual_and_resel(); return true; @@ -5963,11 +5968,8 @@ static void nv_visual(cmdarg_T *cap) * was only one -- webb */ if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1) { - curwin->w_cursor.lnum += - resel_VIsual_line_count * cap->count0 - 1; - if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { - curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; - } + curwin->w_cursor.lnum += resel_VIsual_line_count * cap->count0 - 1; + check_cursor(); } VIsual_mode = resel_VIsual_mode; if (VIsual_mode == 'v') { diff --git a/src/nvim/path.c b/src/nvim/path.c index 674d67e21a..8b110d0ded 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -1682,6 +1682,10 @@ char_u *find_file_name_in_path(char_u *ptr, size_t len, int options, long count, char_u *file_name; char_u *tofree = NULL; + if (len == 0) { + return NULL; + } + if ((options & FNAME_INCL) && *curbuf->b_p_inex != NUL) { tofree = (char_u *)eval_includeexpr((char *)ptr, len); if (tofree != NULL) { diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index d58ca92a2f..e1e7765e06 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1120,7 +1120,35 @@ func Test_visual_block_with_virtualedit() " clean up call term_sendkeys(buf, "\<Esc>") call StopVimInTerminal(buf) - call delete('XTest_beval') + call delete('XTest_block') +endfunc + +func Test_visual_block_ctrl_w_f() + " Emtpy block selected in new buffer should not result in an error. + au! BufNew foo sil norm f + edit foo + + au! BufNew +endfunc + +func Test_visual_reselect_with_count() + " this was causing an illegal memory access + let lines =<< trim END + + + + : + r<sfile> + exe "%norm e3\<c-v>kr\t" + : + + : + END + call writefile(lines, 'XvisualReselect') + source XvisualReselect + + bwipe! + call delete('XvisualReselect') endfunc |