Patch 8.0.1416
Problem:    Crash when searching for a sentence.
Solution:   Return NUL when getting character at MAXCOL. (closes #2468)
Files:      src/misc1.c, src/misc2.c, src/testdir/test_search.vim,
            src/ex_docmd.c


*** ../vim-8.0.1415/src/misc1.c 2017-11-18 18:51:08.125770701 +0100
--- src/misc1.c 2017-12-19 21:10:39.107182729 +0100
***************
*** 2650,2657 ****
      int
  gchar_pos(pos_T *pos)
  {
!     char_u    *ptr = ml_get_pos(pos);
  
  #ifdef FEAT_MBYTE
      if (has_mbyte)
        return (*mb_ptr2char)(ptr);
--- 2650,2661 ----
      int
  gchar_pos(pos_T *pos)
  {
!     char_u    *ptr;
  
+     /* When searching columns is sometimes put at the end of a line. */
+     if (pos->col == MAXCOL)
+       return NUL;
+     ptr = ml_get_pos(pos);
  #ifdef FEAT_MBYTE
      if (has_mbyte)
        return (*mb_ptr2char)(ptr);
*** ../vim-8.0.1415/src/misc2.c 2017-11-18 18:51:08.117770819 +0100
--- src/misc2.c 2017-12-19 21:16:26.944760337 +0100
***************
*** 348,371 ****
      int
  inc(pos_T *lp)
  {
!     char_u  *p = ml_get_pos(lp);
  
!     if (*p != NUL)    /* still within line, move to next char (may be NUL) */
      {
! #ifdef FEAT_MBYTE
!       if (has_mbyte)
        {
!           int l = (*mb_ptr2len)(p);
  
!           lp->col += l;
!           return ((p[l] != NUL) ? 0 : 2);
!       }
  #endif
!       lp->col++;
  #ifdef FEAT_VIRTUALEDIT
!       lp->coladd = 0;
  #endif
!       return ((p[1] != NUL) ? 0 : 2);
      }
      if (lp->lnum != curbuf->b_ml.ml_line_count)     /* there is a next line */
      {
--- 348,376 ----
      int
  inc(pos_T *lp)
  {
!     char_u  *p;
  
!     /* when searching position may be set to end of a line */
!     if (lp->col != MAXCOL)
      {
!       p = ml_get_pos(lp);
!       if (*p != NUL)  /* still within line, move to next char (may be NUL) */
        {
! #ifdef FEAT_MBYTE
!           if (has_mbyte)
!           {
!               int l = (*mb_ptr2len)(p);
  
!               lp->col += l;
!               return ((p[l] != NUL) ? 0 : 2);
!           }
  #endif
!           lp->col++;
  #ifdef FEAT_VIRTUALEDIT
!           lp->coladd = 0;
  #endif
!           return ((p[1] != NUL) ? 0 : 2);
!       }
      }
      if (lp->lnum != curbuf->b_ml.ml_line_count)     /* there is a next line */
      {
*** ../vim-8.0.1415/src/testdir/test_search.vim 2017-12-16 19:59:30.559719124 
+0100
--- src/testdir/test_search.vim 2017-12-19 21:17:46.704212089 +0100
***************
*** 729,731 ****
--- 729,738 ----
    call search(getline("."))
    bwipe!
  endfunc
+ 
+ func Test_search_sentence()
+   new
+   " this used to cause a crash
+   call assert_fails("/\\%'", 'E486')
+   call assert_fails("/", 'E486')
+ endfunc
*** ../vim-8.0.1415/src/ex_docmd.c      2017-11-11 18:16:44.093617922 +0100
--- src/ex_docmd.c      2017-12-19 20:57:16.657068561 +0100
***************
*** 4521,4533 ****
                    if (lnum != MAXLNUM)
                        curwin->w_cursor.lnum = lnum;
                    /*
!                    * Start a forward search at the end of the line.
                     * Start a backward search at the start of the line.
                     * This makes sure we never match in the current
                     * line, and can match anywhere in the
                     * next/previous line.
                     */
!                   if (c == '/')
                        curwin->w_cursor.col = MAXCOL;
                    else
                        curwin->w_cursor.col = 0;
--- 4521,4534 ----
                    if (lnum != MAXLNUM)
                        curwin->w_cursor.lnum = lnum;
                    /*
!                    * Start a forward search at the end of the line (unless
!                    * before the first line).
                     * Start a backward search at the start of the line.
                     * This makes sure we never match in the current
                     * line, and can match anywhere in the
                     * next/previous line.
                     */
!                   if (c == '/' && curwin->w_cursor.lnum > 0)
                        curwin->w_cursor.col = MAXCOL;
                    else
                        curwin->w_cursor.col = 0;
*** ../vim-8.0.1415/src/version.c       2017-12-19 19:42:37.385969952 +0100
--- src/version.c       2017-12-19 21:19:00.939703528 +0100
***************
*** 773,774 ****
--- 773,776 ----
  {   /* Add new patch number below this line */
+ /**/
+     1416,
  /**/

-- 
Never eat yellow snow.

 /// 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].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui