Skip to content

Commit 57df9e8

Browse files
committedJan 20, 2022
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.
1 parent 8aa0e6c commit 57df9e8

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed
 

‎src/ops.c

+2-17
Original file line numberDiff line numberDiff line change
@@ -529,24 +529,9 @@ block_insert(
529529
}
530530

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

535-
// Avoid starting halfway a multi-byte character.
536-
if (b_insert)
537-
{
538-
off = (*mb_head_off)(oldp, oldp + offset + spaces);
539-
spaces -= off;
540-
count -= off;
541-
}
542-
else
543-
{
544-
// spaces fill the gap, the character that's at the edge moves
545-
// right
546-
off = (*mb_head_off)(oldp, oldp + offset);
547-
offset -= off;
548-
}
549-
}
550535
if (spaces < 0) // can happen when the cursor was moved
551536
spaces = 0;
552537

‎src/testdir/test_visual.vim

+9
Original file line numberDiff line numberDiff line change
@@ -1309,5 +1309,14 @@ func Test_visual_reselect_with_count()
13091309
call delete('XvisualReselect')
13101310
endfunc
13111311

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

13131322
" vim: shiftwidth=2 sts=2 expandtab

‎src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
4151,
753755
/**/
754756
4150,
755757
/**/

0 commit comments

Comments
 (0)
Please sign in to comment.