Karsten Hopp 1e16b4
To: vim-dev@vim.org
Karsten Hopp 1e16b4
Subject: Patch 7.2.016
Karsten Hopp 1e16b4
Fcc: outbox
Karsten Hopp 1e16b4
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 1e16b4
Mime-Version: 1.0
Karsten Hopp 1e16b4
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 1e16b4
Content-Transfer-Encoding: 8bit
Karsten Hopp 1e16b4
------------
Karsten Hopp 1e16b4
Karsten Hopp 1e16b4
Patch 7.2.016
Karsten Hopp 1e16b4
Problem:    The pattern being completed may be in freed memory when the
Karsten Hopp 1e16b4
	    command line is being reallocated. (Dominique Pelle)
Karsten Hopp 1e16b4
Solution:   Keep a pointer to the expand_T in the command line structure.
Karsten Hopp 1e16b4
	    Don't use <S-Tab> as CTRL-P when there are no results.  Clear the
Karsten Hopp 1e16b4
	    completion when using a command line from the history.
Karsten Hopp 1e16b4
Files:	    src/ex_getln.c
Karsten Hopp 1e16b4
Karsten Hopp 1e16b4
Karsten Hopp 1e16b4
*** ../vim-7.2.015/src/ex_getln.c	Fri Aug  8 12:58:59 2008
Karsten Hopp 1e16b4
--- src/ex_getln.c	Wed Sep 10 22:43:41 2008
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 31,36 ****
Karsten Hopp 1e16b4
--- 31,38 ----
Karsten Hopp 1e16b4
      int		cmdattr;	/* attributes for prompt */
Karsten Hopp 1e16b4
      int		overstrike;	/* Typing mode on the command line.  Shared by
Karsten Hopp 1e16b4
  				   getcmdline() and put_on_cmdline(). */
Karsten Hopp 1e16b4
+     expand_T	*xpc;		/* struct being used for expansion, xp_pattern
Karsten Hopp 1e16b4
+ 				   may point into cmdbuff */
Karsten Hopp 1e16b4
      int		xp_context;	/* type of expansion */
Karsten Hopp 1e16b4
  # ifdef FEAT_EVAL
Karsten Hopp 1e16b4
      char_u	*xp_arg;	/* user-defined expansion arg */
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 38,44 ****
Karsten Hopp 1e16b4
  # endif
Karsten Hopp 1e16b4
  };
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
! static struct cmdline_info ccline;	/* current cmdline_info */
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  static int	cmd_showtail;		/* Only show path tail in lists ? */
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
--- 40,50 ----
Karsten Hopp 1e16b4
  # endif
Karsten Hopp 1e16b4
  };
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
! /* The current cmdline_info.  It is initialized in getcmdline() and after that
Karsten Hopp 1e16b4
!  * used by other functions.  When invoking getcmdline() recursively it needs
Karsten Hopp 1e16b4
!  * to be saved with save_cmdline() and restored with restore_cmdline().
Karsten Hopp 1e16b4
!  * TODO: make it local to getcmdline() and pass it around. */
Karsten Hopp 1e16b4
! static struct cmdline_info ccline;
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  static int	cmd_showtail;		/* Only show path tail in lists ? */
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 238,243 ****
Karsten Hopp 1e16b4
--- 244,250 ----
Karsten Hopp 1e16b4
      }
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
      ExpandInit(&xpc);
Karsten Hopp 1e16b4
+     ccline.xpc = &xp;;
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  #ifdef FEAT_RIGHTLEFT
Karsten Hopp 1e16b4
      if (curwin->w_p_rl && *curwin->w_p_rlc == 's'
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 408,416 ****
Karsten Hopp 1e16b4
  #endif
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  	/*
Karsten Hopp 1e16b4
! 	 * <S-Tab> works like CTRL-P (unless 'wc' is <S-Tab>).
Karsten Hopp 1e16b4
  	 */
Karsten Hopp 1e16b4
! 	if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles != -1)
Karsten Hopp 1e16b4
  	    c = Ctrl_P;
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  #ifdef FEAT_WILDMENU
Karsten Hopp 1e16b4
--- 415,424 ----
Karsten Hopp 1e16b4
  #endif
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  	/*
Karsten Hopp 1e16b4
! 	 * When there are matching completions to select <S-Tab> works like
Karsten Hopp 1e16b4
! 	 * CTRL-P (unless 'wc' is <S-Tab>).
Karsten Hopp 1e16b4
  	 */
Karsten Hopp 1e16b4
! 	if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0)
Karsten Hopp 1e16b4
  	    c = Ctrl_P;
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  #ifdef FEAT_WILDMENU
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 1513,1518 ****
Karsten Hopp 1e16b4
--- 1521,1527 ----
Karsten Hopp 1e16b4
  		    int		old_firstc;
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  		    vim_free(ccline.cmdbuff);
Karsten Hopp 1e16b4
+ 		    xpc.xp_context = EXPAND_NOTHING;
Karsten Hopp 1e16b4
  		    if (hiscnt == hislen)
Karsten Hopp 1e16b4
  			p = lookfor;	/* back to the old one */
Karsten Hopp 1e16b4
  		    else
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 1839,1844 ****
Karsten Hopp 1e16b4
--- 1848,1854 ----
Karsten Hopp 1e16b4
  #endif
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
      ExpandCleanup(&xpc);
Karsten Hopp 1e16b4
+     ccline.xpc = NULL;
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  #ifdef FEAT_SEARCH_EXTRA
Karsten Hopp 1e16b4
      if (did_incsearch)
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 2508,2513 ****
Karsten Hopp 1e16b4
--- 2518,2537 ----
Karsten Hopp 1e16b4
      }
Karsten Hopp 1e16b4
      mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen + 1);
Karsten Hopp 1e16b4
      vim_free(p);
Karsten Hopp 1e16b4
+ 
Karsten Hopp 1e16b4
+     if (ccline.xpc != NULL
Karsten Hopp 1e16b4
+ 	    && ccline.xpc->xp_pattern != NULL
Karsten Hopp 1e16b4
+ 	    && ccline.xpc->xp_context != EXPAND_NOTHING
Karsten Hopp 1e16b4
+ 	    && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL)
Karsten Hopp 1e16b4
+     {
Karsten Hopp 1e16b4
+ 	int i = ccline.xpc->xp_pattern - p;
Karsten Hopp 1e16b4
+ 
Karsten Hopp 1e16b4
+ 	/* If xp_pattern points inside the old cmdbuff it needs to be adjusted
Karsten Hopp 1e16b4
+ 	 * to point into the newly allocated memory. */
Karsten Hopp 1e16b4
+ 	if (i >= 0 && i <= ccline.cmdlen)
Karsten Hopp 1e16b4
+ 	    ccline.xpc->xp_pattern = ccline.cmdbuff + i;
Karsten Hopp 1e16b4
+     }
Karsten Hopp 1e16b4
+ 
Karsten Hopp 1e16b4
      return OK;
Karsten Hopp 1e16b4
  }
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 2875,2880 ****
Karsten Hopp 1e16b4
--- 2899,2905 ----
Karsten Hopp 1e16b4
      prev_ccline = ccline;
Karsten Hopp 1e16b4
      ccline.cmdbuff = NULL;
Karsten Hopp 1e16b4
      ccline.cmdprompt = NULL;
Karsten Hopp 1e16b4
+     ccline.xpc = NULL;
Karsten Hopp 1e16b4
  }
Karsten Hopp 1e16b4
  
Karsten Hopp 1e16b4
  /*
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 3582,3587 ****
Karsten Hopp 1e16b4
--- 3607,3613 ----
Karsten Hopp 1e16b4
  ExpandInit(xp)
Karsten Hopp 1e16b4
      expand_T	*xp;
Karsten Hopp 1e16b4
  {
Karsten Hopp 1e16b4
+     xp->xp_pattern = NULL;
Karsten Hopp 1e16b4
      xp->xp_backslash = XP_BS_NONE;
Karsten Hopp 1e16b4
  #ifndef BACKSLASH_IN_FILENAME
Karsten Hopp 1e16b4
      xp->xp_shell = FALSE;
Karsten Hopp 1e16b4
*** ../vim-7.2.015/src/version.c	Wed Sep 10 18:25:18 2008
Karsten Hopp 1e16b4
--- src/version.c	Sun Sep 14 14:38:47 2008
Karsten Hopp 1e16b4
***************
Karsten Hopp 1e16b4
*** 678,679 ****
Karsten Hopp 1e16b4
--- 678,681 ----
Karsten Hopp 1e16b4
  {   /* Add new patch number below this line */
Karsten Hopp 1e16b4
+ /**/
Karsten Hopp 1e16b4
+     16,
Karsten Hopp 1e16b4
  /**/
Karsten Hopp 1e16b4
Karsten Hopp 1e16b4
-- 
Karsten Hopp 1e16b4
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 1e16b4
53. To find out what time it is, you send yourself an e-mail and check the
Karsten Hopp 1e16b4
    "Date:" field.
Karsten Hopp 1e16b4
Karsten Hopp 1e16b4
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 1e16b4
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 1e16b4
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 1e16b4
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///