0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

patch 8.2.4956: reading past end of line with "gf" in Visual block mode

Problem:    Reading past end of line with "gf" in Visual block mode.
Solution:   Do not include the NUL in the length.
This commit is contained in:
Bram Moolenaar
2022-05-14 21:29:44 +01:00
parent 788c06a249
commit 395bd1f6d3
3 changed files with 27 additions and 3 deletions

View File

@@ -3671,9 +3671,16 @@ get_visual_text(
} }
if (**pp == NUL) if (**pp == NUL)
*lenp = 0; *lenp = 0;
if (has_mbyte && *lenp > 0) if (*lenp > 0)
// Correct the length to include all bytes of the last character. {
if (has_mbyte)
// Correct the length to include all bytes of the last
// character.
*lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1; *lenp += (*mb_ptr2len)(*pp + (*lenp - 1)) - 1;
else if ((*pp)[*lenp - 1] == NUL)
// Do not include a trailing NUL.
*lenp -= 1;
}
} }
reset_VIsual_and_resel(); reset_VIsual_and_resel();
return OK; return OK;

View File

@@ -138,6 +138,21 @@ func Test_gf_visual()
call assert_equal('Xtest_gf_visual', bufname('%')) call assert_equal('Xtest_gf_visual', bufname('%'))
call assert_equal(3, getcurpos()[1]) call assert_equal(3, getcurpos()[1])
" do not include the NUL at the end
call writefile(['x'], 'X')
let save_enc = &enc
for enc in ['latin1', 'utf-8']
exe "set enc=" .. enc
new
call setline(1, 'X')
set nomodified
exe "normal \<C-V>$gf"
call assert_equal('X', bufname())
bwipe!
endfor
let &enc = save_enc
call delete('X')
" line number in visual area is used for file name " line number in visual area is used for file name
if has('unix') if has('unix')
bwipe! bwipe!

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4956,
/**/ /**/
4955, 4955,
/**/ /**/