Skip to content

Commit

Permalink
patch 9.0.1531: crash when register contents ends up being invalid
Browse files Browse the repository at this point in the history
Problem:    Crash when register contents ends up being invalid.
Solution:   Check "y_array" is not NULL.
  • Loading branch information
brammool committed May 9, 2023
1 parent aa6ba30 commit d1ae836
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/register.c
Expand Up @@ -301,7 +301,7 @@ get_register(
if (copy)
{
// If we run out of memory some or all of the lines are empty.
if (reg->y_size == 0)
if (reg->y_size == 0 || y_current->y_array == NULL)
reg->y_array = NULL;
else
reg->y_array = ALLOC_MULT(char_u *, reg->y_size);
Expand Down
17 changes: 17 additions & 0 deletions src/testdir/test_registers.vim
Expand Up @@ -835,6 +835,23 @@ func Test_end_reg_executing()
bwipe!
endfunc

" This was causing a crash because y_append was ending up being NULL
func Test_zero_y_append()
" Run in a separate Vim instance because changing 'encoding' may cause
" trouble for later tests.
let lines =<< trim END
d
silent ?n
next <sfile>
so
sil! norm 0V€PSP
set enc=latin1

END
call writefile(lines, 'XTest_zero_y_append', 'D')
call RunVim([], [], '-u NONE -i NONE -e -s -S XTest_zero_y_append -c qa\!')
endfunc

" Make sure that y_append is correctly reset
" and the previous register is working as expected
func Test_register_y_append_reset()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

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

0 comments on commit d1ae836

Please sign in to comment.