Karsten Hopp b5c309
To: vim_dev@googlegroups.com
Karsten Hopp b5c309
Subject: Patch 7.3.407
Karsten Hopp b5c309
Fcc: outbox
Karsten Hopp b5c309
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b5c309
Mime-Version: 1.0
Karsten Hopp b5c309
Content-Type: text/plain; charset=UTF-8
Karsten Hopp b5c309
Content-Transfer-Encoding: 8bit
Karsten Hopp b5c309
------------
Karsten Hopp b5c309
Karsten Hopp b5c309
Patch 7.3.407
Karsten Hopp b5c309
Problem:    ":12verbose call F()" may duplicate text while trying to truncate.
Karsten Hopp b5c309
	    (Thinca)
Karsten Hopp b5c309
Solution:   Only truncate when there is not enough room.  Also check the byte
Karsten Hopp b5c309
	    length of the buffer.
Karsten Hopp b5c309
Files:	    src/buffer.c, src/eval.c, src/ex_getln.c, src/message.c,
Karsten Hopp b5c309
	    src/proto/message.pro
Karsten Hopp b5c309
Karsten Hopp b5c309
Karsten Hopp b5c309
*** ../vim-7.3.406/src/buffer.c	2011-12-30 13:39:04.000000000 +0100
Karsten Hopp b5c309
--- src/buffer.c	2012-01-20 18:37:43.000000000 +0100
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 3258,3266 ****
Karsten Hopp b5c309
  	    if (maxlen > 0)
Karsten Hopp b5c309
  	    {
Karsten Hopp b5c309
  		/* make it shorter by removing a bit in the middle */
Karsten Hopp b5c309
! 		len = vim_strsize(buf);
Karsten Hopp b5c309
! 		if (len > maxlen)
Karsten Hopp b5c309
! 		    trunc_string(buf, buf, maxlen);
Karsten Hopp b5c309
  	    }
Karsten Hopp b5c309
  	}
Karsten Hopp b5c309
      }
Karsten Hopp b5c309
--- 3258,3265 ----
Karsten Hopp b5c309
  	    if (maxlen > 0)
Karsten Hopp b5c309
  	    {
Karsten Hopp b5c309
  		/* make it shorter by removing a bit in the middle */
Karsten Hopp b5c309
! 		if (vim_strsize(buf) > maxlen)
Karsten Hopp b5c309
! 		    trunc_string(buf, buf, maxlen, IOSIZE);
Karsten Hopp b5c309
  	    }
Karsten Hopp b5c309
  	}
Karsten Hopp b5c309
      }
Karsten Hopp b5c309
*** ../vim-7.3.406/src/eval.c	2012-01-10 22:26:12.000000000 +0100
Karsten Hopp b5c309
--- src/eval.c	2012-01-20 20:43:32.000000000 +0100
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 22163,22170 ****
Karsten Hopp b5c309
  			s = tv2string(&argvars[i], &tofree, numbuf2, 0);
Karsten Hopp b5c309
  			if (s != NULL)
Karsten Hopp b5c309
  			{
Karsten Hopp b5c309
! 			    trunc_string(s, buf, MSG_BUF_CLEN);
Karsten Hopp b5c309
! 			    msg_puts(buf);
Karsten Hopp b5c309
  			    vim_free(tofree);
Karsten Hopp b5c309
  			}
Karsten Hopp b5c309
  		    }
Karsten Hopp b5c309
--- 22163,22174 ----
Karsten Hopp b5c309
  			s = tv2string(&argvars[i], &tofree, numbuf2, 0);
Karsten Hopp b5c309
  			if (s != NULL)
Karsten Hopp b5c309
  			{
Karsten Hopp b5c309
! 			    if (vim_strsize(s) > MSG_BUF_CLEN)
Karsten Hopp b5c309
! 			    {
Karsten Hopp b5c309
! 				trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
Karsten Hopp b5c309
! 				s = buf;
Karsten Hopp b5c309
! 			    }
Karsten Hopp b5c309
! 			    msg_puts(s);
Karsten Hopp b5c309
  			    vim_free(tofree);
Karsten Hopp b5c309
  			}
Karsten Hopp b5c309
  		    }
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 22252,22259 ****
Karsten Hopp b5c309
  	    s = tv2string(fc->rettv, &tofree, numbuf2, 0);
Karsten Hopp b5c309
  	    if (s != NULL)
Karsten Hopp b5c309
  	    {
Karsten Hopp b5c309
! 		trunc_string(s, buf, MSG_BUF_CLEN);
Karsten Hopp b5c309
! 		smsg((char_u *)_("%s returning %s"), sourcing_name, buf);
Karsten Hopp b5c309
  		vim_free(tofree);
Karsten Hopp b5c309
  	    }
Karsten Hopp b5c309
  	}
Karsten Hopp b5c309
--- 22256,22267 ----
Karsten Hopp b5c309
  	    s = tv2string(fc->rettv, &tofree, numbuf2, 0);
Karsten Hopp b5c309
  	    if (s != NULL)
Karsten Hopp b5c309
  	    {
Karsten Hopp b5c309
! 		if (vim_strsize(s) > MSG_BUF_CLEN)
Karsten Hopp b5c309
! 		{
Karsten Hopp b5c309
! 		    trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
Karsten Hopp b5c309
! 		    s = buf;
Karsten Hopp b5c309
! 		}
Karsten Hopp b5c309
! 		smsg((char_u *)_("%s returning %s"), sourcing_name, s);
Karsten Hopp b5c309
  		vim_free(tofree);
Karsten Hopp b5c309
  	    }
Karsten Hopp b5c309
  	}
Karsten Hopp b5c309
*** ../vim-7.3.406/src/ex_getln.c	2011-12-08 18:44:47.000000000 +0100
Karsten Hopp b5c309
--- src/ex_getln.c	2012-01-20 18:40:46.000000000 +0100
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 5923,5929 ****
Karsten Hopp b5c309
  							      hist[i].hisnum);
Karsten Hopp b5c309
  		    if (vim_strsize(hist[i].hisstr) > (int)Columns - 10)
Karsten Hopp b5c309
  			trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff),
Karsten Hopp b5c309
! 							   (int)Columns - 10);
Karsten Hopp b5c309
  		    else
Karsten Hopp b5c309
  			STRCAT(IObuff, hist[i].hisstr);
Karsten Hopp b5c309
  		    msg_outtrans(IObuff);
Karsten Hopp b5c309
--- 5923,5929 ----
Karsten Hopp b5c309
  							      hist[i].hisnum);
Karsten Hopp b5c309
  		    if (vim_strsize(hist[i].hisstr) > (int)Columns - 10)
Karsten Hopp b5c309
  			trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff),
Karsten Hopp b5c309
! 				  (int)Columns - 10, IOSIZE - STRLEN(IObuff));
Karsten Hopp b5c309
  		    else
Karsten Hopp b5c309
  			STRCAT(IObuff, hist[i].hisstr);
Karsten Hopp b5c309
  		    msg_outtrans(IObuff);
Karsten Hopp b5c309
*** ../vim-7.3.406/src/message.c	2012-01-10 22:26:12.000000000 +0100
Karsten Hopp b5c309
--- src/message.c	2012-01-20 20:38:29.000000000 +0100
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 222,236 ****
Karsten Hopp b5c309
  	    if (enc_utf8)
Karsten Hopp b5c309
  		/* may have up to 18 bytes per cell (6 per char, up to two
Karsten Hopp b5c309
  		 * composing chars) */
Karsten Hopp b5c309
! 		buf = alloc((room + 2) * 18);
Karsten Hopp b5c309
  	    else if (enc_dbcs == DBCS_JPNU)
Karsten Hopp b5c309
  		/* may have up to 2 bytes per cell for euc-jp */
Karsten Hopp b5c309
! 		buf = alloc((room + 2) * 2);
Karsten Hopp b5c309
  	    else
Karsten Hopp b5c309
  #endif
Karsten Hopp b5c309
! 		buf = alloc(room + 2);
Karsten Hopp b5c309
  	    if (buf != NULL)
Karsten Hopp b5c309
! 		trunc_string(s, buf, room);
Karsten Hopp b5c309
  	}
Karsten Hopp b5c309
      }
Karsten Hopp b5c309
      return buf;
Karsten Hopp b5c309
--- 222,237 ----
Karsten Hopp b5c309
  	    if (enc_utf8)
Karsten Hopp b5c309
  		/* may have up to 18 bytes per cell (6 per char, up to two
Karsten Hopp b5c309
  		 * composing chars) */
Karsten Hopp b5c309
! 		len = (room + 2) * 18;
Karsten Hopp b5c309
  	    else if (enc_dbcs == DBCS_JPNU)
Karsten Hopp b5c309
  		/* may have up to 2 bytes per cell for euc-jp */
Karsten Hopp b5c309
! 		len = (room + 2) * 2;
Karsten Hopp b5c309
  	    else
Karsten Hopp b5c309
  #endif
Karsten Hopp b5c309
! 		len = room + 2;
Karsten Hopp b5c309
! 	    buf = alloc(len);
Karsten Hopp b5c309
  	    if (buf != NULL)
Karsten Hopp b5c309
! 		trunc_string(s, buf, room, len);
Karsten Hopp b5c309
  	}
Karsten Hopp b5c309
      }
Karsten Hopp b5c309
      return buf;
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 241,250 ****
Karsten Hopp b5c309
   * "s" and "buf" may be equal.
Karsten Hopp b5c309
   */
Karsten Hopp b5c309
      void
Karsten Hopp b5c309
! trunc_string(s, buf, room)
Karsten Hopp b5c309
      char_u	*s;
Karsten Hopp b5c309
      char_u	*buf;
Karsten Hopp b5c309
      int		room;
Karsten Hopp b5c309
  {
Karsten Hopp b5c309
      int		half;
Karsten Hopp b5c309
      int		len;
Karsten Hopp b5c309
--- 242,252 ----
Karsten Hopp b5c309
   * "s" and "buf" may be equal.
Karsten Hopp b5c309
   */
Karsten Hopp b5c309
      void
Karsten Hopp b5c309
! trunc_string(s, buf, room, buflen)
Karsten Hopp b5c309
      char_u	*s;
Karsten Hopp b5c309
      char_u	*buf;
Karsten Hopp b5c309
      int		room;
Karsten Hopp b5c309
+     int		buflen;
Karsten Hopp b5c309
  {
Karsten Hopp b5c309
      int		half;
Karsten Hopp b5c309
      int		len;
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 257,263 ****
Karsten Hopp b5c309
      len = 0;
Karsten Hopp b5c309
  
Karsten Hopp b5c309
      /* First part: Start of the string. */
Karsten Hopp b5c309
!     for (e = 0; len < half; ++e)
Karsten Hopp b5c309
      {
Karsten Hopp b5c309
  	if (s[e] == NUL)
Karsten Hopp b5c309
  	{
Karsten Hopp b5c309
--- 259,265 ----
Karsten Hopp b5c309
      len = 0;
Karsten Hopp b5c309
  
Karsten Hopp b5c309
      /* First part: Start of the string. */
Karsten Hopp b5c309
!     for (e = 0; len < half && e < buflen; ++e)
Karsten Hopp b5c309
      {
Karsten Hopp b5c309
  	if (s[e] == NUL)
Karsten Hopp b5c309
  	{
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 274,280 ****
Karsten Hopp b5c309
  	if (has_mbyte)
Karsten Hopp b5c309
  	    for (n = (*mb_ptr2len)(s + e); --n > 0; )
Karsten Hopp b5c309
  	    {
Karsten Hopp b5c309
! 		++e;
Karsten Hopp b5c309
  		buf[e] = s[e];
Karsten Hopp b5c309
  	    }
Karsten Hopp b5c309
  #endif
Karsten Hopp b5c309
--- 276,283 ----
Karsten Hopp b5c309
  	if (has_mbyte)
Karsten Hopp b5c309
  	    for (n = (*mb_ptr2len)(s + e); --n > 0; )
Karsten Hopp b5c309
  	    {
Karsten Hopp b5c309
! 		if (++e == buflen)
Karsten Hopp b5c309
! 		    break;
Karsten Hopp b5c309
  		buf[e] = s[e];
Karsten Hopp b5c309
  	    }
Karsten Hopp b5c309
  #endif
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 319,326 ****
Karsten Hopp b5c309
      }
Karsten Hopp b5c309
  
Karsten Hopp b5c309
      /* Set the middle and copy the last part. */
Karsten Hopp b5c309
!     mch_memmove(buf + e, "...", (size_t)3);
Karsten Hopp b5c309
!     STRMOVE(buf + e + 3, s + i);
Karsten Hopp b5c309
  }
Karsten Hopp b5c309
  
Karsten Hopp b5c309
  /*
Karsten Hopp b5c309
--- 322,340 ----
Karsten Hopp b5c309
      }
Karsten Hopp b5c309
  
Karsten Hopp b5c309
      /* Set the middle and copy the last part. */
Karsten Hopp b5c309
!     if (e + 3 < buflen)
Karsten Hopp b5c309
!     {
Karsten Hopp b5c309
! 	mch_memmove(buf + e, "...", (size_t)3);
Karsten Hopp b5c309
! 	len = STRLEN(s + i) + 1;
Karsten Hopp b5c309
! 	if (len >= buflen - e - 3)
Karsten Hopp b5c309
! 	    len = buflen - e - 3 - 1;
Karsten Hopp b5c309
! 	mch_memmove(buf + e + 3, s + i, len);
Karsten Hopp b5c309
! 	buf[e + 3 + len - 1] = NUL;
Karsten Hopp b5c309
!     }
Karsten Hopp b5c309
!     else
Karsten Hopp b5c309
!     {
Karsten Hopp b5c309
! 	buf[e - 1] = NUL;  // make sure it is truncated
Karsten Hopp b5c309
!     }
Karsten Hopp b5c309
  }
Karsten Hopp b5c309
  
Karsten Hopp b5c309
  /*
Karsten Hopp b5c309
*** ../vim-7.3.406/src/proto/message.pro	2011-01-17 20:08:03.000000000 +0100
Karsten Hopp b5c309
--- src/proto/message.pro	2012-01-20 18:51:19.000000000 +0100
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 4,10 ****
Karsten Hopp b5c309
  int msg_attr __ARGS((char_u *s, int attr));
Karsten Hopp b5c309
  int msg_attr_keep __ARGS((char_u *s, int attr, int keep));
Karsten Hopp b5c309
  char_u *msg_strtrunc __ARGS((char_u *s, int force));
Karsten Hopp b5c309
! void trunc_string __ARGS((char_u *s, char_u *buf, int room));
Karsten Hopp b5c309
  void reset_last_sourcing __ARGS((void));
Karsten Hopp b5c309
  void msg_source __ARGS((int attr));
Karsten Hopp b5c309
  int emsg_not_now __ARGS((void));
Karsten Hopp b5c309
--- 4,10 ----
Karsten Hopp b5c309
  int msg_attr __ARGS((char_u *s, int attr));
Karsten Hopp b5c309
  int msg_attr_keep __ARGS((char_u *s, int attr, int keep));
Karsten Hopp b5c309
  char_u *msg_strtrunc __ARGS((char_u *s, int force));
Karsten Hopp b5c309
! void trunc_string __ARGS((char_u *s, char_u *buf, int room, int buflen));
Karsten Hopp b5c309
  void reset_last_sourcing __ARGS((void));
Karsten Hopp b5c309
  void msg_source __ARGS((int attr));
Karsten Hopp b5c309
  int emsg_not_now __ARGS((void));
Karsten Hopp b5c309
*** ../vim-7.3.406/src/version.c	2012-01-20 17:57:47.000000000 +0100
Karsten Hopp b5c309
--- src/version.c	2012-01-20 20:42:23.000000000 +0100
Karsten Hopp b5c309
***************
Karsten Hopp b5c309
*** 716,717 ****
Karsten Hopp b5c309
--- 716,719 ----
Karsten Hopp b5c309
  {   /* Add new patch number below this line */
Karsten Hopp b5c309
+ /**/
Karsten Hopp b5c309
+     407,
Karsten Hopp b5c309
  /**/
Karsten Hopp b5c309
Karsten Hopp b5c309
-- 
Karsten Hopp b5c309
Hanson's Treatment of Time:
Karsten Hopp b5c309
	There are never enough hours in a day, but always too
Karsten Hopp b5c309
	many days before Saturday.
Karsten Hopp b5c309
Karsten Hopp b5c309
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp b5c309
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp b5c309
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp b5c309
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///