File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -251,18 +251,23 @@ linelen(int *has_tab)
251251 int save ;
252252 int len ;
253253
254- /* find the first non-blank character */
254+ // Get the line. If it's empty bail out early (could be the empty string
255+ // for an unloaded buffer).
255256 line = ml_get_curline ();
257+ if (* line == NUL )
258+ return 0 ;
259+
260+ // find the first non-blank character
256261 first = skipwhite (line );
257262
258- /* find the character after the last non-blank character */
263+ // find the character after the last non-blank character
259264 for (last = first + STRLEN (first );
260265 last > first && VIM_ISWHITE (last [-1 ]); -- last )
261266 ;
262267 save = * last ;
263268 * last = NUL ;
264- len = linetabsize (line ); /* get line length */
265- if (has_tab != NULL ) /* check for embedded TAB */
269+ len = linetabsize (line ); // get line length
270+ if (has_tab != NULL ) // check for embedded TAB
266271 * has_tab = (vim_strchr (first , TAB ) != NULL );
267272 * last = save ;
268273
Original file line number Diff line number Diff line change 11" Tests for the various 'formatoptions' settings
2+
3+ source check.vim
4+
25func Test_text_format ()
36 enew !
47
@@ -489,3 +492,20 @@ func Test_format_list_auto()
489492 bwipe!
490493 set fo & ai & bs &
491494endfunc
495+
496+ func Test_crash_github_issue_5095 ()
497+ CheckFeature autocmd
498+
499+ " This used to segfault, see https://github.com/vim/vim/issues/5095
500+ augroup testing
501+ au BufNew x center
502+ augroup END
503+
504+ next ! x
505+
506+ bw
507+ augroup testing
508+ au !
509+ augroup END
510+ augroup ! testing
511+ endfunc
Original file line number Diff line number Diff line change @@ -741,6 +741,8 @@ static char *(features[]) =
741741
742742static int included_patches [] =
743743{ /* Add new patch number below this line */
744+ /**/
745+ 2198 ,
744746/**/
745747 2197 ,
746748/**/
You can’t perform that action at this time.
0 commit comments