Skip to content

Commit

Permalink
patch 9.1.0399: block_editing errors out when using del
Browse files Browse the repository at this point in the history
Problem:  block_editing errors out when using del
          (@jamarley)
Solution: Change ins_len from size_t to int and
          properly check that it doesn't become negative

There is a check in os.c that verifies that `ins_len` does not become
negative:
```
if (pre_textlen >= 0 && (ins_len = len - pre_textlen - offset) > 0)
```
However this only works, if ins_len can actually become negative and
unfortunately, ins_len has been declared as `size_t` so instead of
becoming negative it will wrap around and be very large.

So let's define it as integer, after which the condition above
properly catches this condition.

fixes: #14734
closes: #14735

Signed-off-by: Christian Brabandt <cb@256bit.org>
  • Loading branch information
chrisbra committed May 8, 2024
1 parent cb36918 commit d5c8c09
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ op_insert(oparg_T *oap, long count1)

if (oap->block_mode)
{
size_t ins_len;
int ins_len;
char_u *firstline, *ins_text;
struct block_def bd2;
int did_indent = FALSE;
Expand Down
8 changes: 8 additions & 0 deletions src/testdir/test_visual.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2031,4 +2031,12 @@ func Test_getregion_maxcol()
bwipe!
endfunc

func Test_visual_block_cursor_delete()
new
call setline(1, 'ab')
exe ":norm! $\<c-v>hI\<Del>\<ESC>"
call assert_equal(['b'], getline(1, 1))
bwipe!
endfunc

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

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

0 comments on commit d5c8c09

Please sign in to comment.