Skip to content

Commit

Permalink
patch 8.2.4359: crash when repeatedly using :retab
Browse files Browse the repository at this point in the history
Problem:    crash when repeatedly using :retab.
Solution:   Bail out when the line is getting too long.
  • Loading branch information
brammool committed Feb 12, 2022
1 parent 90a5716 commit 6e28703
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/indent.c
Expand Up @@ -1750,6 +1750,11 @@ ex_retab(exarg_T *eap)
if (ptr[col] == NUL)
break;
vcol += chartabsize(ptr + col, (colnr_T)vcol);
if (vcol >= MAXCOL)
{
emsg(_(e_resulting_text_too_long));
break;
}
if (has_mbyte)
col += (*mb_ptr2len)(ptr + col);
else
Expand Down
19 changes: 19 additions & 0 deletions src/testdir/test_retab.vim
Expand Up @@ -70,6 +70,8 @@ func Test_retab()
call assert_equal(" a b c ", Retab('!', 3))
call assert_equal(" a b c ", Retab('', 5))
call assert_equal(" a b c ", Retab('!', 5))

set tabstop& expandtab&
endfunc

func Test_retab_error()
Expand All @@ -80,4 +82,21 @@ func Test_retab_error()
call assert_fails('ret 80000000000000000000', 'E475:')
endfunc

func Test_retab_endless()
new
call setline(1, "\t0\t")
let caught = 'no'
try
while 1
set ts=4000
retab 4
endwhile
catch /E1240/
let caught = 'yes'
endtry
bwipe!
set tabstop&
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 */
/**/
4359,
/**/
4358,
/**/
Expand Down

0 comments on commit 6e28703

Please sign in to comment.