Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.677
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.677
Problem:    buf_spname() is used inconsistently.
Solution:   Make the return type a char_u pointer.  Check the size of the
	    returned string.
Files:	    src/buffer.c, src/proto/buffer.pro, src/ex_cmds2.c,
	    src/ex_docmd.c, src/memline.c, src/screen.c


*** ../vim-7.3.676/src/buffer.c	2012-10-03 17:12:43.000000000 +0200
--- src/buffer.c	2012-10-03 18:14:34.000000000 +0200
***************
*** 2635,2641 ****
  	    continue;
  	msg_putchar('\n');
  	if (buf_spname(buf) != NULL)
! 	    STRCPY(NameBuff, buf_spname(buf));
  	else
  	    home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
  
--- 2635,2641 ----
  	    continue;
  	msg_putchar('\n');
  	if (buf_spname(buf) != NULL)
! 	    vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
  	else
  	    home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
  
***************
*** 3350,3356 ****
  	else
  	{
  	    if (buf_spname(curbuf) != NULL)
! 		i_name = (char_u *)buf_spname(curbuf);
  	    else		    /* use file name only in icon */
  		i_name = gettail(curbuf->b_ffname);
  	    *i_str = NUL;
--- 3350,3356 ----
  	else
  	{
  	    if (buf_spname(curbuf) != NULL)
! 		i_name = buf_spname(curbuf);
  	    else		    /* use file name only in icon */
  		i_name = gettail(curbuf->b_ffname);
  	    *i_str = NUL;
***************
*** 3766,3772 ****
  	case STL_FILENAME:
  	    fillable = FALSE;	/* don't change ' ' to fillchar */
  	    if (buf_spname(wp->w_buffer) != NULL)
! 		STRCPY(NameBuff, buf_spname(wp->w_buffer));
  	    else
  	    {
  		t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname
--- 3766,3772 ----
  	case STL_FILENAME:
  	    fillable = FALSE;	/* don't change ' ' to fillchar */
  	    if (buf_spname(wp->w_buffer) != NULL)
! 		vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1);
  	    else
  	    {
  		t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname
***************
*** 5244,5250 ****
   * Return special buffer name.
   * Returns NULL when the buffer has a normal file name.
   */
!     char *
  buf_spname(buf)
      buf_T	*buf;
  {
--- 5244,5250 ----
   * Return special buffer name.
   * Returns NULL when the buffer has a normal file name.
   */
!     char_u *
  buf_spname(buf)
      buf_T	*buf;
  {
***************
*** 5263,5271 ****
  		goto win_found;
  win_found:
  	if (win != NULL && win->w_llist_ref != NULL)
! 	    return _(msg_loclist);
  	else
! 	    return _(msg_qflist);
      }
  #endif
  #ifdef FEAT_QUICKFIX
--- 5263,5271 ----
  		goto win_found;
  win_found:
  	if (win != NULL && win->w_llist_ref != NULL)
! 	    return (char_u *)_(msg_loclist);
  	else
! 	    return (char_u *)_(msg_qflist);
      }
  #endif
  #ifdef FEAT_QUICKFIX
***************
*** 5274,5285 ****
      if (bt_nofile(buf))
      {
  	if (buf->b_sfname != NULL)
! 	    return (char *)buf->b_sfname;
! 	return _("[Scratch]");
      }
  #endif
      if (buf->b_fname == NULL)
! 	return _("[No Name]");
      return NULL;
  }
  
--- 5274,5285 ----
      if (bt_nofile(buf))
      {
  	if (buf->b_sfname != NULL)
! 	    return buf->b_sfname;
! 	return (char_u *)_("[Scratch]");
      }
  #endif
      if (buf->b_fname == NULL)
! 	return (char_u *)_("[No Name]");
      return NULL;
  }
  
*** ../vim-7.3.676/src/proto/buffer.pro	2012-07-10 15:18:18.000000000 +0200
--- src/proto/buffer.pro	2012-10-03 18:17:58.000000000 +0200
***************
*** 51,57 ****
  void do_modelines __ARGS((int flags));
  int read_viminfo_bufferlist __ARGS((vir_T *virp, int writing));
  void write_viminfo_bufferlist __ARGS((FILE *fp));
! char *buf_spname __ARGS((buf_T *buf));
  void buf_addsign __ARGS((buf_T *buf, int id, linenr_T lnum, int typenr));
  linenr_T buf_change_sign_type __ARGS((buf_T *buf, int markId, int typenr));
  int buf_getsigntype __ARGS((buf_T *buf, linenr_T lnum, int type));
--- 51,57 ----
  void do_modelines __ARGS((int flags));
  int read_viminfo_bufferlist __ARGS((vir_T *virp, int writing));
  void write_viminfo_bufferlist __ARGS((FILE *fp));
! char_u *buf_spname __ARGS((buf_T *buf));
  void buf_addsign __ARGS((buf_T *buf, int id, linenr_T lnum, int typenr));
  linenr_T buf_change_sign_type __ARGS((buf_T *buf, int markId, int typenr));
  int buf_getsigntype __ARGS((buf_T *buf, linenr_T lnum, int type));
*** ../vim-7.3.676/src/ex_cmds2.c	2012-06-29 12:57:03.000000000 +0200
--- src/ex_cmds2.c	2012-10-03 18:15:26.000000000 +0200
***************
*** 1688,1695 ****
  	    msg_didout = FALSE;
  	}
  	if (EMSG2(_("E162: No write since last change for buffer \"%s\""),
! 		    buf_spname(buf) != NULL ? (char_u *)buf_spname(buf) :
! 		    buf->b_fname))
  	{
  	    save = no_wait_return;
  	    no_wait_return = FALSE;
--- 1688,1694 ----
  	    msg_didout = FALSE;
  	}
  	if (EMSG2(_("E162: No write since last change for buffer \"%s\""),
! 		    buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname))
  	{
  	    save = no_wait_return;
  	    no_wait_return = FALSE;
*** ../vim-7.3.676/src/ex_docmd.c	2012-09-18 16:47:00.000000000 +0200
--- src/ex_docmd.c	2012-10-03 18:15:47.000000000 +0200
***************
*** 7602,7608 ****
  	    msg_putchar(bufIsChanged(wp->w_buffer) ? '+' : ' ');
  	    msg_putchar(' ');
  	    if (buf_spname(wp->w_buffer) != NULL)
! 		STRCPY(IObuff, buf_spname(wp->w_buffer));
  	    else
  		home_replace(wp->w_buffer, wp->w_buffer->b_fname,
  							IObuff, IOSIZE, TRUE);
--- 7602,7608 ----
  	    msg_putchar(bufIsChanged(wp->w_buffer) ? '+' : ' ');
  	    msg_putchar(' ');
  	    if (buf_spname(wp->w_buffer) != NULL)
! 		vim_strncpy(IObuff, buf_spname(wp->w_buffer), IOSIZE - 1);
  	    else
  		home_replace(wp->w_buffer, wp->w_buffer->b_fname,
  							IObuff, IOSIZE, TRUE);
*** ../vim-7.3.676/src/memline.c	2011-10-26 11:44:15.000000000 +0200
--- src/memline.c	2012-10-03 18:18:23.000000000 +0200
***************
*** 780,788 ****
  	need_wait_return = TRUE;	/* call wait_return later */
  	++no_wait_return;
  	(void)EMSG2(_("E303: Unable to open swap file for \"%s\", recovery impossible"),
! 		    buf_spname(buf) != NULL
! 			? (char_u *)buf_spname(buf)
! 			: buf->b_fname);
  	--no_wait_return;
      }
  
--- 780,786 ----
  	need_wait_return = TRUE;	/* call wait_return later */
  	++no_wait_return;
  	(void)EMSG2(_("E303: Unable to open swap file for \"%s\", recovery impossible"),
! 		    buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname);
  	--no_wait_return;
      }
  
***************
*** 1315,1321 ****
      smsg((char_u *)_("Using swap file \"%s\""), NameBuff);
  
      if (buf_spname(curbuf) != NULL)
! 	STRCPY(NameBuff, buf_spname(curbuf));
      else
  	home_replace(NULL, curbuf->b_ffname, NameBuff, MAXPATHL, TRUE);
      smsg((char_u *)_("Original file \"%s\""), NameBuff);
--- 1313,1319 ----
      smsg((char_u *)_("Using swap file \"%s\""), NameBuff);
  
      if (buf_spname(curbuf) != NULL)
! 	vim_strncpy(NameBuff, buf_spname(curbuf), MAXPATHL - 1);
      else
  	home_replace(NULL, curbuf->b_ffname, NameBuff, MAXPATHL, TRUE);
      smsg((char_u *)_("Original file \"%s\""), NameBuff);
*** ../vim-7.3.676/src/screen.c	2012-08-23 18:55:50.000000000 +0200
--- src/screen.c	2012-10-03 18:17:25.000000000 +0200
***************
*** 9876,9882 ****
      buf_T	*buf;
  {
      if (buf_spname(buf) != NULL)
! 	STRCPY(NameBuff, buf_spname(buf));
      else
  	home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
      trans_characters(NameBuff, MAXPATHL);
--- 9876,9882 ----
      buf_T	*buf;
  {
      if (buf_spname(buf) != NULL)
! 	vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
      else
  	home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
      trans_characters(NameBuff, MAXPATHL);
*** ../vim-7.3.676/src/version.c	2012-10-03 18:06:55.000000000 +0200
--- src/version.c	2012-10-03 18:22:18.000000000 +0200
***************
*** 721,722 ****
--- 721,724 ----
  {   /* Add new patch number below this line */
+ /**/
+     677,
  /**/

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~

 /// Bram Moolenaar -- Bram@Moolenaar.net -- 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    ///