Patch 8.1.2198
Problem:    Crash when using :center in autocommand.
Solution:   Bail out early for an empty line. (Dominique pelle, closes #5095)
Files:      src/ex_cmds.c, src/testdir/test_textformat.vim


*** ../vim-8.1.2197/src/ex_cmds.c       2019-10-20 18:17:08.367431701 +0200
--- src/ex_cmds.c       2019-10-21 23:08:03.033053099 +0200
***************
*** 251,268 ****
      int           save;
      int           len;
  
!     /* find the first non-blank character */
      line = ml_get_curline();
      first = skipwhite(line);
  
!     /* find the character after the last non-blank character */
      for (last = first + STRLEN(first);
                                last > first && VIM_ISWHITE(last[-1]); --last)
        ;
      save = *last;
      *last = NUL;
!     len = linetabsize(line);          /* get line length */
!     if (has_tab != NULL)              /* check for embedded TAB */
        *has_tab = (vim_strchr(first, TAB) != NULL);
      *last = save;
  
--- 251,273 ----
      int           save;
      int           len;
  
!     // Get the line.  If it's empty bail out early (could be the empty string
!     // for an unloaded buffer).
      line = ml_get_curline();
+     if (*line == NUL)
+       return 0;
+ 
+     // find the first non-blank character
      first = skipwhite(line);
  
!     // find the character after the last non-blank character
      for (last = first + STRLEN(first);
                                last > first && VIM_ISWHITE(last[-1]); --last)
        ;
      save = *last;
      *last = NUL;
!     len = linetabsize(line);          // get line length
!     if (has_tab != NULL)              // check for embedded TAB
        *has_tab = (vim_strchr(first, TAB) != NULL);
      *last = save;
  
*** ../vim-8.1.2197/src/testdir/test_textformat.vim     2019-01-11 
22:15:00.519123428 +0100
--- src/testdir/test_textformat.vim     2019-10-21 23:04:32.782096728 +0200
***************
*** 1,4 ****
--- 1,7 ----
  " Tests for the various 'formatoptions' settings
+ 
+ source check.vim
+ 
  func Test_text_format()
    enew!
  
***************
*** 489,491 ****
--- 492,511 ----
    bwipe!
    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
*** ../vim-8.1.2197/src/version.c       2019-10-20 22:27:06.373331908 +0200
--- src/version.c       2019-10-21 23:00:14.479449866 +0200
***************
*** 743,744 ****
--- 743,746 ----
  {   /* Add new patch number below this line */
+ /**/
+     2198,
  /**/

-- 
DENNIS: Oh, very nice. King, eh!  I expect you've got a palace and fine
        clothes and courtiers and plenty of food.  And how d'you get that?  By
        exploiting the workers! By hanging on to outdated imperialist dogma
        which perpetuates the social and economic differences in our society!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201910212126.x9LLQQlt015443%40masaka.moolenaar.net.

Raspunde prin e-mail lui