Karsten Hopp 81c285
To: vim-dev@vim.org
Karsten Hopp 81c285
Subject: Patch 7.2.239
Karsten Hopp 81c285
Fcc: outbox
Karsten Hopp 81c285
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 81c285
Mime-Version: 1.0
Karsten Hopp 81c285
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 81c285
Content-Transfer-Encoding: 8bit
Karsten Hopp 81c285
------------
Karsten Hopp 81c285
Karsten Hopp 81c285
Patch 7.2.239
Karsten Hopp 81c285
Problem:    Using :diffpatch twice or when patching fails causes memory
Karsten Hopp 81c285
	    corruption and/or a crash.  (Bryan Venteicher)
Karsten Hopp 81c285
Solution:   Detect missing output file.  Avoid using non-existing buffer.
Karsten Hopp 81c285
Files:	    src/diff.c
Karsten Hopp 81c285
Karsten Hopp 81c285
Karsten Hopp 81c285
*** ../vim-7.2.238/src/diff.c	2009-05-14 22:19:19.000000000 +0200
Karsten Hopp 81c285
--- src/diff.c	2009-07-22 16:06:21.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 893,898 ****
Karsten Hopp 81c285
--- 893,899 ----
Karsten Hopp 81c285
      char_u	*browseFile = NULL;
Karsten Hopp 81c285
      int		browse_flag = cmdmod.browse;
Karsten Hopp 81c285
  #endif
Karsten Hopp 81c285
+     struct stat st;
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #ifdef FEAT_BROWSE
Karsten Hopp 81c285
      if (cmdmod.browse)
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 999,1042 ****
Karsten Hopp 81c285
      STRCAT(buf, ".rej");
Karsten Hopp 81c285
      mch_remove(buf);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
!     if (curbuf->b_fname != NULL)
Karsten Hopp 81c285
      {
Karsten Hopp 81c285
! 	newname = vim_strnsave(curbuf->b_fname,
Karsten Hopp 81c285
  					  (int)(STRLEN(curbuf->b_fname) + 4));
Karsten Hopp 81c285
! 	if (newname != NULL)
Karsten Hopp 81c285
! 	    STRCAT(newname, ".new");
Karsten Hopp 81c285
!     }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #ifdef FEAT_GUI
Karsten Hopp 81c285
!     need_mouse_correct = TRUE;
Karsten Hopp 81c285
  #endif
Karsten Hopp 81c285
!     /* don't use a new tab page, each tab page has its own diffs */
Karsten Hopp 81c285
!     cmdmod.tab = 0;
Karsten Hopp 81c285
! 
Karsten Hopp 81c285
!     if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL)
Karsten Hopp 81c285
!     {
Karsten Hopp 81c285
! 	/* Pretend it was a ":split fname" command */
Karsten Hopp 81c285
! 	eap->cmdidx = CMD_split;
Karsten Hopp 81c285
! 	eap->arg = tmp_new;
Karsten Hopp 81c285
! 	do_exedit(eap, old_curwin);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
! 	if (curwin != old_curwin)		/* split must have worked */
Karsten Hopp 81c285
  	{
Karsten Hopp 81c285
! 	    /* Set 'diff', 'scrollbind' on and 'wrap' off. */
Karsten Hopp 81c285
! 	    diff_win_options(curwin, TRUE);
Karsten Hopp 81c285
! 	    diff_win_options(old_curwin, TRUE);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
! 	    if (newname != NULL)
Karsten Hopp 81c285
  	    {
Karsten Hopp 81c285
! 		/* do a ":file filename.new" on the patched buffer */
Karsten Hopp 81c285
! 		eap->arg = newname;
Karsten Hopp 81c285
! 		ex_file(eap);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #ifdef FEAT_AUTOCMD
Karsten Hopp 81c285
! 		/* Do filetype detection with the new name. */
Karsten Hopp 81c285
! 		if (au_has_group((char_u *)"filetypedetect"))
Karsten Hopp 81c285
! 		    do_cmdline_cmd((char_u *)":doau filetypedetect BufRead");
Karsten Hopp 81c285
  #endif
Karsten Hopp 81c285
  	    }
Karsten Hopp 81c285
  	}
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
--- 1000,1050 ----
Karsten Hopp 81c285
      STRCAT(buf, ".rej");
Karsten Hopp 81c285
      mch_remove(buf);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
!     /* Only continue if the output file was created. */
Karsten Hopp 81c285
!     if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0)
Karsten Hopp 81c285
! 	EMSG(_("E816: Cannot read patch output"));
Karsten Hopp 81c285
!     else
Karsten Hopp 81c285
      {
Karsten Hopp 81c285
! 	if (curbuf->b_fname != NULL)
Karsten Hopp 81c285
! 	{
Karsten Hopp 81c285
! 	    newname = vim_strnsave(curbuf->b_fname,
Karsten Hopp 81c285
  					  (int)(STRLEN(curbuf->b_fname) + 4));
Karsten Hopp 81c285
! 	    if (newname != NULL)
Karsten Hopp 81c285
! 		STRCAT(newname, ".new");
Karsten Hopp 81c285
! 	}
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #ifdef FEAT_GUI
Karsten Hopp 81c285
! 	need_mouse_correct = TRUE;
Karsten Hopp 81c285
  #endif
Karsten Hopp 81c285
! 	/* don't use a new tab page, each tab page has its own diffs */
Karsten Hopp 81c285
! 	cmdmod.tab = 0;
Karsten Hopp 81c285
  
Karsten Hopp 81c285
! 	if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL)
Karsten Hopp 81c285
  	{
Karsten Hopp 81c285
! 	    /* Pretend it was a ":split fname" command */
Karsten Hopp 81c285
! 	    eap->cmdidx = CMD_split;
Karsten Hopp 81c285
! 	    eap->arg = tmp_new;
Karsten Hopp 81c285
! 	    do_exedit(eap, old_curwin);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
! 	    /* check that split worked and editing tmp_new */
Karsten Hopp 81c285
! 	    if (curwin != old_curwin && win_valid(old_curwin))
Karsten Hopp 81c285
  	    {
Karsten Hopp 81c285
! 		/* Set 'diff', 'scrollbind' on and 'wrap' off. */
Karsten Hopp 81c285
! 		diff_win_options(curwin, TRUE);
Karsten Hopp 81c285
! 		diff_win_options(old_curwin, TRUE);
Karsten Hopp 81c285
! 
Karsten Hopp 81c285
! 		if (newname != NULL)
Karsten Hopp 81c285
! 		{
Karsten Hopp 81c285
! 		    /* do a ":file filename.new" on the patched buffer */
Karsten Hopp 81c285
! 		    eap->arg = newname;
Karsten Hopp 81c285
! 		    ex_file(eap);
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #ifdef FEAT_AUTOCMD
Karsten Hopp 81c285
! 		    /* Do filetype detection with the new name. */
Karsten Hopp 81c285
! 		    if (au_has_group((char_u *)"filetypedetect"))
Karsten Hopp 81c285
! 			do_cmdline_cmd((char_u *)":doau filetypedetect BufRead");
Karsten Hopp 81c285
  #endif
Karsten Hopp 81c285
+ 		}
Karsten Hopp 81c285
  	    }
Karsten Hopp 81c285
  	}
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
*** ../vim-7.2.238/src/version.c	2009-07-22 14:27:33.000000000 +0200
Karsten Hopp 81c285
--- src/version.c	2009-07-22 16:21:29.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 678,679 ****
Karsten Hopp 81c285
--- 678,681 ----
Karsten Hopp 81c285
  {   /* Add new patch number below this line */
Karsten Hopp 81c285
+ /**/
Karsten Hopp 81c285
+     239,
Karsten Hopp 81c285
  /**/
Karsten Hopp 81c285
Karsten Hopp 81c285
-- 
Karsten Hopp 81c285
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 81c285
97. Your mother tells you to remember something, and you look for
Karsten Hopp 81c285
    a File/Save command.
Karsten Hopp 81c285
Karsten Hopp 81c285
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 81c285
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 81c285
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 81c285
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///