mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #17385 from seandewar/vim-8.2.4359
vim-patch:8.2.{4359,4362,4363,4364}: crash when repeatedly using :retab
This commit is contained in:
commit
7a7ac004f0
@ -814,7 +814,11 @@ void ex_retab(exarg_T *eap)
|
|||||||
// len is actual number of white characters used
|
// len is actual number of white characters used
|
||||||
len = num_spaces + num_tabs;
|
len = num_spaces + num_tabs;
|
||||||
old_len = (long)STRLEN(ptr);
|
old_len = (long)STRLEN(ptr);
|
||||||
long new_len = old_len - col + start_col + len + 1;
|
const long new_len = old_len - col + start_col + len + 1;
|
||||||
|
if (new_len <= 0 || new_len >= MAXCOL) {
|
||||||
|
emsg(_(e_resulting_text_too_long));
|
||||||
|
break;
|
||||||
|
}
|
||||||
new_line = xmalloc(new_len);
|
new_line = xmalloc(new_len);
|
||||||
|
|
||||||
if (start_col > 0) {
|
if (start_col > 0) {
|
||||||
@ -847,6 +851,10 @@ void ex_retab(exarg_T *eap)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol);
|
vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol);
|
||||||
|
if (vcol >= MAXCOL) {
|
||||||
|
emsg(_(e_resulting_text_too_long));
|
||||||
|
break;
|
||||||
|
}
|
||||||
col += utfc_ptr2len(ptr + col);
|
col += utfc_ptr2len(ptr + col);
|
||||||
}
|
}
|
||||||
if (new_line == NULL) { // out of memory
|
if (new_line == NULL) { // out of memory
|
||||||
|
@ -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_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 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"));
|
EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM"));
|
||||||
|
@ -16,7 +16,9 @@ typedef int colnr_T;
|
|||||||
/// Maximal (invalid) line number
|
/// Maximal (invalid) line number
|
||||||
enum { MAXLNUM = 0x7fffffff, };
|
enum { MAXLNUM = 0x7fffffff, };
|
||||||
/// Maximal column number
|
/// Maximal column number
|
||||||
enum { MAXCOL = INT_MAX, };
|
/// MAXCOL used to be INT_MAX, but with 64 bit ints that results in running
|
||||||
|
/// out of memory when trying to allocate a very long line.
|
||||||
|
enum { MAXCOL = 0x7fffffff, };
|
||||||
// Minimum line number
|
// Minimum line number
|
||||||
enum { MINLNUM = 1, };
|
enum { MINLNUM = 1, };
|
||||||
// minimum column number
|
// minimum column number
|
||||||
|
@ -69,6 +69,8 @@ func Test_retab()
|
|||||||
call assert_equal(" a b c ", Retab('!', 3))
|
call assert_equal(" a b c ", Retab('!', 3))
|
||||||
call assert_equal(" a b c ", Retab('', 5))
|
call assert_equal(" a b c ", Retab('', 5))
|
||||||
call assert_equal(" a b c ", Retab('!', 5))
|
call assert_equal(" a b c ", Retab('!', 5))
|
||||||
|
|
||||||
|
set tabstop& expandtab&
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_retab_error()
|
func Test_retab_error()
|
||||||
@ -78,3 +80,22 @@ func Test_retab_error()
|
|||||||
call assert_fails('ret 10000', 'E475:')
|
call assert_fails('ret 10000', 'E475:')
|
||||||
call assert_fails('ret 80000000000000000000', 'E475:')
|
call assert_fails('ret 80000000000000000000', 'E475:')
|
||||||
endfunc
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user