vim-patch:8.2.4359: crash when repeatedly using :retab

Problem:    crash when repeatedly using :retab.
Solution:   Bail out when the line is getting too long.
6e28703a8e

Cherry-pick e_resulting_text_too_long from v8.2.3492; put it in globals.h as
it will eventually be used in other files.

Add a modeline to test_retab.vim
This commit is contained in:
Sean Dewar 2022-02-12 18:23:38 +00:00
parent 05c3d02380
commit 1b0d6bcd53
No known key found for this signature in database
GPG Key ID: 08CC2C83AD41B581
3 changed files with 27 additions and 0 deletions

View File

@ -847,6 +847,10 @@ void ex_retab(exarg_T *eap)
break;
}
vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol);
if (vcol >= MAXCOL) {
emsg(_(e_resulting_text_too_long));
break;
}
col += utfc_ptr2len(ptr + col);
}
if (new_line == NULL) { // out of memory

View File

@ -1000,6 +1000,8 @@ EXTERN char e_non_empty_string_required[] INIT(= N_("E1142: Non-empty string req
EXTERN char e_cannot_define_autocommands_for_all_events[] INIT(= N_("E1155: Cannot define autocommands for ALL events"));
EXTERN char e_resulting_text_too_long[] INIT(= N_("E1240: Resulting text too long"));
EXTERN char e_highlight_group_name_too_long[] INIT(= N_("E1249: Highlight group name too long"));
EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM"));

View File

@ -69,6 +69,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()
@ -78,3 +80,22 @@ func Test_retab_error()
call assert_fails('ret 10000', 'E475:')
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