Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
patch 8.2.4151: reading beyond the end of a line
Problem:    Reading beyond the end of a line.
Solution:   For block insert only use the offset for correcting the length.
  • Loading branch information
brammool committed Jan 20, 2022
1 parent 8aa0e6c commit 57df9e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/ops.c
Expand Up @@ -529,24 +529,9 @@ block_insert(
}

if (has_mbyte && spaces > 0)
{
int off;
// avoid copying part of a multi-byte character
offset -= (*mb_head_off)(oldp, oldp + offset);

// Avoid starting halfway a multi-byte character.
if (b_insert)
{
off = (*mb_head_off)(oldp, oldp + offset + spaces);
spaces -= off;
count -= off;
}
else
{
// spaces fill the gap, the character that's at the edge moves
// right
off = (*mb_head_off)(oldp, oldp + offset);
offset -= off;
}
}
if (spaces < 0) // can happen when the cursor was moved
spaces = 0;

Expand Down
9 changes: 9 additions & 0 deletions src/testdir/test_visual.vim
Expand Up @@ -1309,5 +1309,14 @@ func Test_visual_reselect_with_count()
call delete('XvisualReselect')
endfunc

func Test_visual_block_insert_round_off()
new
" The number of characters are tuned to fill a 4096 byte allocated block,
" so that valgrind reports going over the end.
call setline(1, ['xxxxx', repeat('0', 1350), "\t", repeat('x', 60)])
exe "normal gg0\<C-V>GI" .. repeat('0', 1320) .. "\<Esc>"
bwipe!
endfunc


" vim: shiftwidth=2 sts=2 expandtab
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4151,
/**/
4150,
/**/
Expand Down

0 comments on commit 57df9e8

Please sign in to comment.