Patch 8.2.4120
Problem: Block insert goes over the end of the line.
Solution: Handle invalid byte better. Fix inserting the wrong text.
Files: src/ops.c, src/testdir/test_visual.vim
*** ../vim-8.2.4119/src/ops.c 2022-01-15 18:25:04.661419379 +0000
--- src/ops.c 2022-01-17 17:28:18.293949520 +0000
***************
*** 536,559 ****
if (b_insert)
{
off = (*mb_head_off)(oldp, oldp + offset + spaces);
}
else
{
! off = (*mb_off_next)(oldp, oldp + offset);
! offset += off;
}
- spaces -= off;
- count -= off;
}
if (spaces < 0) // can happen when the cursor was moved
spaces = 0;
! newp = alloc(STRLEN(oldp) + s_len + count + 1);
if (newp == NULL)
continue;
// copy up to shifted part
! mch_memmove(newp, oldp, (size_t)(offset));
oldp += offset;
// insert pre-padding
--- 536,564 ----
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;
! // Make sure the allocated size matches what is actually copied below.
! newp = alloc(STRLEN(oldp) + spaces + s_len
! + (spaces > 0 && !bdp->is_short ? ts_val - spaces : 0)
! + count + 1);
if (newp == NULL)
continue;
// copy up to shifted part
! mch_memmove(newp, oldp, (size_t)offset);
oldp += offset;
// insert pre-padding
***************
*** 564,577 ****
mch_memmove(newp + startcol, s, (size_t)s_len);
offset += s_len;
! if (spaces && !bdp->is_short)
{
! // insert post-padding
! vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces));
! // We're splitting a TAB, don't copy it.
! oldp++;
! // We allowed for that TAB, remember this now
! count++;
}
if (spaces > 0)
--- 569,589 ----
mch_memmove(newp + startcol, s, (size_t)s_len);
offset += s_len;
! if (spaces > 0 && !bdp->is_short)
{
! if (*oldp == TAB)
! {
! // insert post-padding
! vim_memset(newp + offset + spaces, ' ',
! (size_t)(ts_val - spaces));
! // we're splitting a TAB, don't copy it
! oldp++;
! // We allowed for that TAB, remember this now
! count++;
! }
! else
! // Not a TAB, no extra spaces
! count = spaces;
}
if (spaces > 0)
***************
*** 1598,1604 ****
oap->start_vcol = t;
}
else if (oap->op_type == OP_APPEND
! && oap->end.col + oap->end.coladd
>= curbuf->b_op_start_orig.col
+ curbuf->b_op_start_orig.coladd)
{
--- 1610,1616 ----
oap->start_vcol = t;
}
else if (oap->op_type == OP_APPEND
! && oap->start.col + oap->start.coladd
>= curbuf->b_op_start_orig.col
+ curbuf->b_op_start_orig.coladd)
{
*** ../vim-8.2.4119/src/testdir/test_visual.vim 2021-12-16 10:05:18.619384919 +0000
--- src/testdir/test_visual.vim 2022-01-17 17:16:12.994871556 +0000
***************
*** 1278,1283 ****
--- 1278,1292 ----
au! BufNew
endfunc
+ func Test_visual_block_append_invalid_char()
+ " this was going over the end of the line
+ new
+ call setline(1, [' let xxx', 'xxxxxˆ', 'xxxxxxxxxxx'])
+ exe "normal 0\<C-V>jjA-\<Esc>"
+ call assert_equal([' - let xxx', 'xxxxx -ˆ', 'xxxxxxxx-xxx'], getline(1, 3))
+ bwipe!
+ endfunc
+
func Test_visual_reselect_with_count()
" this was causing an illegal memory access
let lines =<< trim END
*** ../vim-8.2.4119/src/version.c 2022-01-17 11:22:22.823956310 +0000
--- src/version.c 2022-01-17 17:29:56.537835592 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4120,
/**/
--
WOMAN: Dennis, there's some lovely filth down here. Oh -- how d'you do?
ARTHUR: How do you do, good lady. I am Arthur, King of the Britons.
Who's castle is that?
WOMAN: King of the who?
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///