cf262a2
To: vim-dev@vim.org
cf262a2
Subject: Patch 7.2.347
cf262a2
Fcc: outbox
cf262a2
From: Bram Moolenaar <Bram@moolenaar.net>
cf262a2
Mime-Version: 1.0
cf262a2
Content-Type: text/plain; charset=UTF-8
cf262a2
Content-Transfer-Encoding: 8bit
cf262a2
------------
cf262a2
cf262a2
Patch 7.2.347
cf262a2
Problem:    Crash when executing <expr> mapping redefines that same mapping.
cf262a2
Solution:   Save the values used before evaluating the expression.
cf262a2
Files:	    src/getchar.c
cf262a2
cf262a2
cf262a2
*** ../vim-7.2.346/src/getchar.c	2009-11-11 16:23:37.000000000 +0100
cf262a2
--- src/getchar.c	2010-01-27 17:30:42.000000000 +0100
cf262a2
***************
cf262a2
*** 2389,2394 ****
cf262a2
--- 2389,2405 ----
cf262a2
  		    /* complete match */
cf262a2
  		    if (keylen >= 0 && keylen <= typebuf.tb_len)
cf262a2
  		    {
cf262a2
+ #ifdef FEAT_EVAL
cf262a2
+ 			int save_m_expr;
cf262a2
+ 			int save_m_noremap;
cf262a2
+ 			int save_m_silent;
cf262a2
+ 			char_u *save_m_keys;
cf262a2
+ 			char_u *save_m_str;
cf262a2
+ #else
cf262a2
+ # define save_m_noremap mp->m_noremap
cf262a2
+ # define save_m_silent mp->m_silent
cf262a2
+ #endif
cf262a2
+ 
cf262a2
  			/* write chars to script file(s) */
cf262a2
  			if (keylen > typebuf.tb_maplen)
cf262a2
  			    gotchars(typebuf.tb_buf + typebuf.tb_off
cf262a2
***************
cf262a2
*** 2431,2436 ****
cf262a2
--- 2442,2457 ----
cf262a2
  #endif
cf262a2
  
cf262a2
  #ifdef FEAT_EVAL
cf262a2
+ 			/* Copy the values from *mp that are used, because
cf262a2
+ 			 * evaluating the expression may invoke a function
cf262a2
+ 			 * that redefines the mapping, thereby making *mp
cf262a2
+ 			 * invalid. */
cf262a2
+ 			save_m_expr = mp->m_expr;
cf262a2
+ 			save_m_noremap = mp->m_noremap;
cf262a2
+ 			save_m_silent = mp->m_silent;
cf262a2
+ 			save_m_keys = NULL;  /* only saved when needed */
cf262a2
+ 			save_m_str = NULL;  /* only saved when needed */
cf262a2
+ 
cf262a2
  			/*
cf262a2
  			 * Handle ":map <expr>": evaluate the {rhs} as an
cf262a2
  			 * expression.  Save and restore the typeahead so that
cf262a2
***************
cf262a2
*** 2446,2452 ****
cf262a2
  			    if (tabuf.typebuf_valid)
cf262a2
  			    {
cf262a2
  				vgetc_busy = 0;
cf262a2
! 				s = eval_map_expr(mp->m_str, NUL);
cf262a2
  				vgetc_busy = save_vgetc_busy;
cf262a2
  			    }
cf262a2
  			    else
cf262a2
--- 2467,2475 ----
cf262a2
  			    if (tabuf.typebuf_valid)
cf262a2
  			    {
cf262a2
  				vgetc_busy = 0;
cf262a2
! 				save_m_keys = vim_strsave(mp->m_keys);
cf262a2
! 				save_m_str = vim_strsave(mp->m_str);
cf262a2
! 				s = eval_map_expr(save_m_str, NUL);
cf262a2
  				vgetc_busy = save_vgetc_busy;
cf262a2
  			    }
cf262a2
  			    else
cf262a2
***************
cf262a2
*** 2470,2486 ****
cf262a2
  			else
cf262a2
  			{
cf262a2
  			    i = ins_typebuf(s,
cf262a2
! 				    mp->m_noremap != REMAP_YES
cf262a2
! 					    ? mp->m_noremap
cf262a2
! 					    : STRNCMP(s, mp->m_keys,
cf262a2
  							  (size_t)keylen) != 0
cf262a2
  						     ? REMAP_YES : REMAP_SKIP,
cf262a2
! 				0, TRUE, cmd_silent || mp->m_silent);
cf262a2
  #ifdef FEAT_EVAL
cf262a2
! 			    if (mp->m_expr)
cf262a2
  				vim_free(s);
cf262a2
  #endif
cf262a2
  			}
cf262a2
  			if (i == FAIL)
cf262a2
  			{
cf262a2
  			    c = -1;
cf262a2
--- 2493,2517 ----
cf262a2
  			else
cf262a2
  			{
cf262a2
  			    i = ins_typebuf(s,
cf262a2
! 				    save_m_noremap != REMAP_YES
cf262a2
! 					    ? save_m_noremap
cf262a2
! 					    : STRNCMP(s,
cf262a2
! #ifdef FEAT_EVAL
cf262a2
! 					   save_m_keys != NULL ? save_m_keys :
cf262a2
! #endif
cf262a2
! 						      mp->m_keys,
cf262a2
  							  (size_t)keylen) != 0
cf262a2
  						     ? REMAP_YES : REMAP_SKIP,
cf262a2
! 				0, TRUE, cmd_silent || save_m_silent);
cf262a2
  #ifdef FEAT_EVAL
cf262a2
! 			    if (save_m_expr)
cf262a2
  				vim_free(s);
cf262a2
  #endif
cf262a2
  			}
cf262a2
+ #ifdef FEAT_EVAL
cf262a2
+ 			vim_free(save_m_keys);
cf262a2
+ 			vim_free(save_m_str);
cf262a2
+ #endif
cf262a2
  			if (i == FAIL)
cf262a2
  			{
cf262a2
  			    c = -1;
cf262a2
*** ../vim-7.2.346/src/version.c	2010-01-27 16:31:00.000000000 +0100
cf262a2
--- src/version.c	2010-01-27 17:27:32.000000000 +0100
cf262a2
***************
cf262a2
*** 683,684 ****
cf262a2
--- 683,686 ----
cf262a2
  {   /* Add new patch number below this line */
cf262a2
+ /**/
cf262a2
+     347,
cf262a2
  /**/
cf262a2
cf262a2
-- 
cf262a2
hundred-and-one symptoms of being an internet addict:
cf262a2
156. You forget your friend's name but not her e-mail address.
cf262a2
cf262a2
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
cf262a2
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
cf262a2
\\\        download, build and distribute -- http://www.A-A-P.org        ///
cf262a2
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///