Karsten Hopp 6588f1
To: vim_dev@googlegroups.com
Karsten Hopp 6588f1
Subject: Patch 7.3.916
Karsten Hopp 6588f1
Fcc: outbox
Karsten Hopp 6588f1
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6588f1
Mime-Version: 1.0
Karsten Hopp 6588f1
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6588f1
Content-Transfer-Encoding: 8bit
Karsten Hopp 6588f1
------------
Karsten Hopp 6588f1
Karsten Hopp 6588f1
Patch 7.3.916
Karsten Hopp 6588f1
Problem:    Using freed memory when pasting with the mouse (Issue 130).
Karsten Hopp 6588f1
Solution:   Get the byte value early. (hint by Dominique Pelle)
Karsten Hopp 6588f1
Files:	    src/buffer.c
Karsten Hopp 6588f1
Karsten Hopp 6588f1
Karsten Hopp 6588f1
*** ../vim-7.3.915/src/buffer.c	2013-04-15 12:27:30.000000000 +0200
Karsten Hopp 6588f1
--- src/buffer.c	2013-04-24 16:45:38.000000000 +0200
Karsten Hopp 6588f1
***************
Karsten Hopp 6588f1
*** 3506,3512 ****
Karsten Hopp 6588f1
      char_u	*p;
Karsten Hopp 6588f1
      char_u	*s;
Karsten Hopp 6588f1
      char_u	*t;
Karsten Hopp 6588f1
!     char_u	*linecont;
Karsten Hopp 6588f1
  #ifdef FEAT_EVAL
Karsten Hopp 6588f1
      win_T	*o_curwin;
Karsten Hopp 6588f1
      buf_T	*o_curbuf;
Karsten Hopp 6588f1
--- 3506,3512 ----
Karsten Hopp 6588f1
      char_u	*p;
Karsten Hopp 6588f1
      char_u	*s;
Karsten Hopp 6588f1
      char_u	*t;
Karsten Hopp 6588f1
!     int		byteval;
Karsten Hopp 6588f1
  #ifdef FEAT_EVAL
Karsten Hopp 6588f1
      win_T	*o_curwin;
Karsten Hopp 6588f1
      buf_T	*o_curbuf;
Karsten Hopp 6588f1
***************
Karsten Hopp 6588f1
*** 3573,3584 ****
Karsten Hopp 6588f1
  	fillchar = '-';
Karsten Hopp 6588f1
  #endif
Karsten Hopp 6588f1
  
Karsten Hopp 6588f1
!     /*
Karsten Hopp 6588f1
!      * Get line & check if empty (cursorpos will show "0-1").
Karsten Hopp 6588f1
!      * If inversion is possible we use it. Else '=' characters are used.
Karsten Hopp 6588f1
!      */
Karsten Hopp 6588f1
!     linecont = ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE);
Karsten Hopp 6588f1
!     empty_line = (*linecont == NUL);
Karsten Hopp 6588f1
  
Karsten Hopp 6588f1
      groupdepth = 0;
Karsten Hopp 6588f1
      p = out;
Karsten Hopp 6588f1
--- 3573,3593 ----
Karsten Hopp 6588f1
  	fillchar = '-';
Karsten Hopp 6588f1
  #endif
Karsten Hopp 6588f1
  
Karsten Hopp 6588f1
!     /* Get line & check if empty (cursorpos will show "0-1").  Note that
Karsten Hopp 6588f1
!      * p will become invalid when getting another buffer line. */
Karsten Hopp 6588f1
!     p = ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE);
Karsten Hopp 6588f1
!     empty_line = (*p == NUL);
Karsten Hopp 6588f1
! 
Karsten Hopp 6588f1
!     /* Get the byte value now, in case we need it below. This is more
Karsten Hopp 6588f1
!      * efficient than making a copy of the line. */
Karsten Hopp 6588f1
!     if (wp->w_cursor.col > (colnr_T)STRLEN(p))
Karsten Hopp 6588f1
! 	byteval = 0;
Karsten Hopp 6588f1
!     else
Karsten Hopp 6588f1
! #ifdef FEAT_MBYTE
Karsten Hopp 6588f1
! 	byteval = (*mb_ptr2char)(p + wp->w_cursor.col);
Karsten Hopp 6588f1
! #else
Karsten Hopp 6588f1
! 	byteval = p[wp->w_cursor.col];
Karsten Hopp 6588f1
! #endif
Karsten Hopp 6588f1
  
Karsten Hopp 6588f1
      groupdepth = 0;
Karsten Hopp 6588f1
      p = out;
Karsten Hopp 6588f1
***************
Karsten Hopp 6588f1
*** 3956,3971 ****
Karsten Hopp 6588f1
  	case STL_BYTEVAL_X:
Karsten Hopp 6588f1
  	    base = 'X';
Karsten Hopp 6588f1
  	case STL_BYTEVAL:
Karsten Hopp 6588f1
! 	    if (wp->w_cursor.col > (colnr_T)STRLEN(linecont))
Karsten Hopp 6588f1
! 		num = 0;
Karsten Hopp 6588f1
! 	    else
Karsten Hopp 6588f1
! 	    {
Karsten Hopp 6588f1
! #ifdef FEAT_MBYTE
Karsten Hopp 6588f1
! 		num = (*mb_ptr2char)(linecont + wp->w_cursor.col);
Karsten Hopp 6588f1
! #else
Karsten Hopp 6588f1
! 		num = linecont[wp->w_cursor.col];
Karsten Hopp 6588f1
! #endif
Karsten Hopp 6588f1
! 	    }
Karsten Hopp 6588f1
  	    if (num == NL)
Karsten Hopp 6588f1
  		num = 0;
Karsten Hopp 6588f1
  	    else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC)
Karsten Hopp 6588f1
--- 3965,3971 ----
Karsten Hopp 6588f1
  	case STL_BYTEVAL_X:
Karsten Hopp 6588f1
  	    base = 'X';
Karsten Hopp 6588f1
  	case STL_BYTEVAL:
Karsten Hopp 6588f1
! 	    num = byteval;
Karsten Hopp 6588f1
  	    if (num == NL)
Karsten Hopp 6588f1
  		num = 0;
Karsten Hopp 6588f1
  	    else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC)
Karsten Hopp 6588f1
*** ../vim-7.3.915/src/version.c	2013-04-24 16:33:58.000000000 +0200
Karsten Hopp 6588f1
--- src/version.c	2013-04-24 16:51:24.000000000 +0200
Karsten Hopp 6588f1
***************
Karsten Hopp 6588f1
*** 730,731 ****
Karsten Hopp 6588f1
--- 730,733 ----
Karsten Hopp 6588f1
  {   /* Add new patch number below this line */
Karsten Hopp 6588f1
+ /**/
Karsten Hopp 6588f1
+     916,
Karsten Hopp 6588f1
  /**/
Karsten Hopp 6588f1
Karsten Hopp 6588f1
-- 
Karsten Hopp 6588f1
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 6588f1
228. You spend Saturday night making the counter on your home page
Karsten Hopp 6588f1
     pass that 2000 mark.
Karsten Hopp 6588f1
Karsten Hopp 6588f1
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6588f1
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6588f1
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 6588f1
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///