073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.539
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.539 (after 7.4.530)
073263
Problem:    Crash when computing buffer count.  Problem with range for user
073263
	    commands.  Line range wrong in Visual area.
073263
Solution:   Avoid segfault in compute_buffer_local_count().  Check for
073263
	    CMD_USER when checking type of range. (Marcin Szamotulski)
073263
Files:	    runtime/doc/windows.txt, src/ex_docmd.c
073263
073263
073263
*** ../vim-7.4.538/runtime/doc/windows.txt	2014-11-27 16:22:42.738413084 +0100
073263
--- runtime/doc/windows.txt	2014-11-30 14:34:30.241835431 +0100
073263
***************
073263
*** 1026,1032 ****
073263
  		Actually, the buffer isn't completely deleted, it is removed
073263
  		from the buffer list |unlisted-buffer| and option values,
073263
  		variables and mappings/abbreviations for the buffer are
073263
! 		cleared.
073263
  
073263
  :bdelete[!] {bufname}						*E93* *E94*
073263
  		Like ":bdelete[!] [N]", but buffer given by name.  Note that a
073263
--- 1029,1039 ----
073263
  		Actually, the buffer isn't completely deleted, it is removed
073263
  		from the buffer list |unlisted-buffer| and option values,
073263
  		variables and mappings/abbreviations for the buffer are
073263
! 		cleared. Examples: >
073263
! 		    :.,$-bdelete    " delete buffers from the current one to
073263
! 				    " last but one
073263
! 		    :%bdelete	    " delete all buffers
073263
! <
073263
  
073263
  :bdelete[!] {bufname}						*E93* *E94*
073263
  		Like ":bdelete[!] [N]", but buffer given by name.  Note that a
073263
***************
073263
*** 1050,1056 ****
073263
  		Like |:bdelete|, but really delete the buffer.  Everything
073263
  		related to the buffer is lost.  All marks in this buffer
073263
  		become invalid, option settings are lost, etc.  Don't use this
073263
! 		unless you know what you are doing.
073263
  
073263
  :[N]bun[load][!]				*:bun* *:bunload* *E515*
073263
  :bun[load][!] [N]
073263
--- 1057,1067 ----
073263
  		Like |:bdelete|, but really delete the buffer.  Everything
073263
  		related to the buffer is lost.  All marks in this buffer
073263
  		become invalid, option settings are lost, etc.  Don't use this
073263
! 		unless you know what you are doing. Examples: >
073263
! 		    :.+,$bwipeout   " wipe out all buffers after the current
073263
! 				    " one
073263
! 		    :%bwipeout	    " wipe out all buffers
073263
! <
073263
  
073263
  :[N]bun[load][!]				*:bun* *:bunload* *E515*
073263
  :bun[load][!] [N]
073263
*** ../vim-7.4.538/src/ex_docmd.c	2014-11-27 18:32:58.528564550 +0100
073263
--- src/ex_docmd.c	2014-11-30 14:40:28.521847466 +0100
073263
***************
073263
*** 1694,1699 ****
073263
--- 1694,1700 ----
073263
      int	    offset;
073263
  {
073263
      buf_T   *buf;
073263
+     buf_T   *nextbuf;
073263
      int     count = offset;
073263
  
073263
      buf = firstbuf;
073263
***************
073263
*** 1701,1715 ****
073263
  	buf = buf->b_next;
073263
      while (count != 0)
073263
      {
073263
! 	count += (count < 0) ? 1 : -1;
073263
! 	if (buf->b_prev == NULL)
073263
  	    break;
073263
! 	buf = (count < 0) ? buf->b_prev : buf->b_next;
073263
  	if (addr_type == ADDR_LOADED_BUFFERS)
073263
  	    /* skip over unloaded buffers */
073263
! 	    while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL)
073263
! 		buf = (count < 0) ? buf->b_prev : buf->b_next;
073263
      }
073263
      return buf->b_fnum;
073263
  }
073263
  
073263
--- 1702,1731 ----
073263
  	buf = buf->b_next;
073263
      while (count != 0)
073263
      {
073263
! 	count += (offset < 0) ? 1 : -1;
073263
! 	nextbuf = (offset < 0) ? buf->b_prev : buf->b_next;
073263
! 	if (nextbuf == NULL)
073263
  	    break;
073263
! 	buf = nextbuf;
073263
  	if (addr_type == ADDR_LOADED_BUFFERS)
073263
  	    /* skip over unloaded buffers */
073263
! 	    while (buf->b_ml.ml_mfp == NULL)
073263
! 	    {
073263
! 		nextbuf = (offset < 0) ? buf->b_prev : buf->b_next;
073263
! 		if (nextbuf == NULL)
073263
! 		    break;
073263
! 		buf = nextbuf;
073263
! 	    }
073263
      }
073263
+     /* we might have gone too far, last buffer is not loadedd */
073263
+     if (addr_type == ADDR_LOADED_BUFFERS)
073263
+ 	while (buf->b_ml.ml_mfp == NULL)
073263
+ 	{
073263
+ 	    nextbuf = (offset >= 0) ? buf->b_prev : buf->b_next;
073263
+ 	    if (nextbuf == NULL)
073263
+ 		break;
073263
+ 	    buf = nextbuf;
073263
+ 	}
073263
      return buf->b_fnum;
073263
  }
073263
  
073263
***************
073263
*** 2113,2119 ****
073263
   * is equal to the lower.
073263
   */
073263
  
073263
!     if (ea.cmdidx != CMD_SIZE)
073263
  	ea.addr_type = cmdnames[(int)ea.cmdidx].cmd_addr_type;
073263
      else
073263
  	ea.addr_type = ADDR_LINES;
073263
--- 2129,2135 ----
073263
   * is equal to the lower.
073263
   */
073263
  
073263
!     if (ea.cmdidx != CMD_USER && ea.cmdidx != CMD_SIZE)
073263
  	ea.addr_type = cmdnames[(int)ea.cmdidx].cmd_addr_type;
073263
      else
073263
  	ea.addr_type = ADDR_LINES;
073263
***************
073263
*** 2153,2158 ****
073263
--- 2169,2175 ----
073263
  	{
073263
  	    if (*ea.cmd == '%')		    /* '%' - all lines */
073263
  	    {
073263
+ 		buf_T	*buf;
073263
  		++ea.cmd;
073263
  		switch (ea.addr_type)
073263
  		{
073263
***************
073263
*** 2160,2168 ****
073263
  			ea.line1 = 1;
073263
  			ea.line2 = curbuf->b_ml.ml_line_count;
073263
  			break;
073263
- 		    case ADDR_WINDOWS:
073263
  		    case ADDR_LOADED_BUFFERS:
073263
  		    case ADDR_UNLOADED_BUFFERS:
073263
  		    case ADDR_TABS:
073263
  			errormsg = (char_u *)_(e_invrange);
073263
  			goto doend;
073263
--- 2177,2197 ----
073263
  			ea.line1 = 1;
073263
  			ea.line2 = curbuf->b_ml.ml_line_count;
073263
  			break;
073263
  		    case ADDR_LOADED_BUFFERS:
073263
+ 			buf = firstbuf;
073263
+ 			while (buf->b_next != NULL && buf->b_ml.ml_mfp == NULL)
073263
+ 			    buf = buf->b_next;
073263
+ 			ea.line1 = buf->b_fnum;
073263
+ 			buf = lastbuf;
073263
+ 			while (buf->b_prev != NULL && buf->b_ml.ml_mfp == NULL)
073263
+ 			    buf = buf->b_prev;
073263
+ 			ea.line2 = buf->b_fnum;
073263
+ 			break;
073263
  		    case ADDR_UNLOADED_BUFFERS:
073263
+ 			ea.line1 = firstbuf->b_fnum;
073263
+ 			ea.line2 = lastbuf->b_fnum;
073263
+ 			break;
073263
+ 		    case ADDR_WINDOWS:
073263
  		    case ADDR_TABS:
073263
  			errormsg = (char_u *)_(e_invrange);
073263
  			goto doend;
073263
***************
073263
*** 4463,4469 ****
073263
  		n = getdigits(&cmd);
073263
  	    if (addr_type == ADDR_LOADED_BUFFERS
073263
  		    || addr_type == ADDR_UNLOADED_BUFFERS)
073263
! 		lnum = compute_buffer_local_count(addr_type, lnum, n);
073263
  	    else if (i == '-')
073263
  		lnum -= n;
073263
  	    else
073263
--- 4492,4498 ----
073263
  		n = getdigits(&cmd);
073263
  	    if (addr_type == ADDR_LOADED_BUFFERS
073263
  		    || addr_type == ADDR_UNLOADED_BUFFERS)
073263
! 		lnum = compute_buffer_local_count(addr_type, lnum, (i == '-') ? -1 * n : n);
073263
  	    else if (i == '-')
073263
  		lnum -= n;
073263
  	    else
073263
***************
073263
*** 4485,4493 ****
073263
  			lnum = 0;
073263
  			break;
073263
  		    }
073263
! 		    c = LAST_TAB_NR;
073263
! 		    if (lnum >= c)
073263
! 			lnum = c;
073263
  		    break;
073263
  		case ADDR_WINDOWS:
073263
  		    if (lnum < 0)
073263
--- 4514,4521 ----
073263
  			lnum = 0;
073263
  			break;
073263
  		    }
073263
! 		    if (lnum >= LAST_TAB_NR)
073263
! 			lnum = LAST_TAB_NR;
073263
  		    break;
073263
  		case ADDR_WINDOWS:
073263
  		    if (lnum < 0)
073263
***************
073263
*** 4495,4503 ****
073263
  			lnum = 0;
073263
  			break;
073263
  		    }
073263
! 		    c = LAST_WIN_NR;
073263
! 		    if (lnum > c)
073263
! 			lnum = c;
073263
  		    break;
073263
  		case ADDR_LOADED_BUFFERS:
073263
  		case ADDR_UNLOADED_BUFFERS:
073263
--- 4523,4530 ----
073263
  			lnum = 0;
073263
  			break;
073263
  		    }
073263
! 		    if (lnum >= LAST_WIN_NR)
073263
! 			lnum = LAST_WIN_NR;
073263
  		    break;
073263
  		case ADDR_LOADED_BUFFERS:
073263
  		case ADDR_UNLOADED_BUFFERS:
073263
*** ../vim-7.4.538/src/version.c	2014-11-30 13:34:16.893626683 +0100
073263
--- src/version.c	2014-11-30 14:33:29.622510487 +0100
073263
***************
073263
*** 743,744 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     539,
073263
  /**/
073263
073263
-- 
073263
SOLDIER: What?  Ridden on a horse?
073263
ARTHUR:  Yes!
073263
SOLDIER: You're using coconuts!
073263
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///