mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
vim-patch:8.1.2198: crash when using :center in autocommand
Problem: Crash when using :center in autocommand.
Solution: Bail out early for an empty line. (Dominique pelle, closes vim/vim#5095)
396b7c78c0
Cherry-pick 'src/testdir/check.vim' changes from patch 8.1.1544.
This commit is contained in:
@@ -326,14 +326,19 @@ static int linelen(int *has_tab)
|
||||
int save;
|
||||
int len;
|
||||
|
||||
/* find the first non-blank character */
|
||||
// Get the line. If it's empty bail out early (could be the empty string
|
||||
// for an unloaded buffer).
|
||||
line = get_cursor_line_ptr();
|
||||
if (*line == NUL) {
|
||||
return 0;
|
||||
}
|
||||
// find the first non-blank character
|
||||
first = skipwhite(line);
|
||||
|
||||
/* find the character after the last non-blank character */
|
||||
// find the character after the last non-blank character
|
||||
for (last = first + STRLEN(first);
|
||||
last > first && ascii_iswhite(last[-1]); --last)
|
||||
;
|
||||
last > first && ascii_iswhite(last[-1]); last--) {
|
||||
}
|
||||
save = *last;
|
||||
*last = NUL;
|
||||
// Get line length.
|
||||
|
@@ -1,6 +1,30 @@
|
||||
source shared.vim
|
||||
source term_util.vim
|
||||
|
||||
" Command to check for the presence of a feature.
|
||||
command -nargs=1 CheckFeature call CheckFeature(<f-args>)
|
||||
func CheckFeature(name)
|
||||
if !has(a:name)
|
||||
throw 'Skipped: ' .. a:name .. ' feature missing'
|
||||
endif
|
||||
endfunc
|
||||
|
||||
" Command to check for the presence of a working option.
|
||||
command -nargs=1 CheckOption call CheckOption(<f-args>)
|
||||
func CheckOption(name)
|
||||
if !exists('+' .. a:name)
|
||||
throw 'Skipped: ' .. a:name .. ' option not supported'
|
||||
endif
|
||||
endfunc
|
||||
|
||||
" Command to check for the presence of a function.
|
||||
command -nargs=1 CheckFunction call CheckFunction(<f-args>)
|
||||
func CheckFunction(name)
|
||||
if !exists('*' .. a:name)
|
||||
throw 'Skipped: ' .. a:name .. ' function missing'
|
||||
endif
|
||||
endfunc
|
||||
|
||||
" Command to check that making screendumps is supported.
|
||||
" Caller must source screendump.vim
|
||||
command CheckScreendump call CheckScreendump()
|
||||
|
@@ -1,4 +1,7 @@
|
||||
" Tests for the various 'formatoptions' settings
|
||||
|
||||
source check.vim
|
||||
|
||||
func Test_text_format()
|
||||
enew!
|
||||
|
||||
@@ -490,6 +493,23 @@ func Test_format_list_auto()
|
||||
set fo& ai& bs&
|
||||
endfunc
|
||||
|
||||
func Test_crash_github_issue_5095()
|
||||
CheckFeature autocmd
|
||||
|
||||
" This used to segfault, see https://github.com/vim/vim/issues/5095
|
||||
augroup testing
|
||||
au BufNew x center
|
||||
augroup END
|
||||
|
||||
next! x
|
||||
|
||||
bw
|
||||
augroup testing
|
||||
au!
|
||||
augroup END
|
||||
augroup! testing
|
||||
endfunc
|
||||
|
||||
" Test for formatting multi-byte text with 'fo=t'
|
||||
func Test_tw_2_fo_t()
|
||||
new
|
||||
|
Reference in New Issue
Block a user