summaryrefslogtreecommitdiff
path: root/source/ap/vim/patches/7.2.347
blob: e5fa17d48dbaaad343f6616e86b84bafb87b9365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
To: vim-dev@vim.org
Subject: Patch 7.2.347
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.2.347
Problem:    Crash when executing <expr> mapping redefines that same mapping.
Solution:   Save the values used before evaluating the expression.
Files:	    src/getchar.c


*** ../vim-7.2.346/src/getchar.c	2009-11-11 16:23:37.000000000 +0100
--- src/getchar.c	2010-01-27 17:30:42.000000000 +0100
***************
*** 2389,2394 ****
--- 2389,2405 ----
  		    /* complete match */
  		    if (keylen >= 0 && keylen <= typebuf.tb_len)
  		    {
+ #ifdef FEAT_EVAL
+ 			int save_m_expr;
+ 			int save_m_noremap;
+ 			int save_m_silent;
+ 			char_u *save_m_keys;
+ 			char_u *save_m_str;
+ #else
+ # define save_m_noremap mp->m_noremap
+ # define save_m_silent mp->m_silent
+ #endif
+ 
  			/* write chars to script file(s) */
  			if (keylen > typebuf.tb_maplen)
  			    gotchars(typebuf.tb_buf + typebuf.tb_off
***************
*** 2431,2436 ****
--- 2442,2457 ----
  #endif
  
  #ifdef FEAT_EVAL
+ 			/* Copy the values from *mp that are used, because
+ 			 * evaluating the expression may invoke a function
+ 			 * that redefines the mapping, thereby making *mp
+ 			 * invalid. */
+ 			save_m_expr = mp->m_expr;
+ 			save_m_noremap = mp->m_noremap;
+ 			save_m_silent = mp->m_silent;
+ 			save_m_keys = NULL;  /* only saved when needed */
+ 			save_m_str = NULL;  /* only saved when needed */
+ 
  			/*
  			 * Handle ":map <expr>": evaluate the {rhs} as an
  			 * expression.  Save and restore the typeahead so that
***************
*** 2446,2452 ****
  			    if (tabuf.typebuf_valid)
  			    {
  				vgetc_busy = 0;
! 				s = eval_map_expr(mp->m_str, NUL);
  				vgetc_busy = save_vgetc_busy;
  			    }
  			    else
--- 2467,2475 ----
  			    if (tabuf.typebuf_valid)
  			    {
  				vgetc_busy = 0;
! 				save_m_keys = vim_strsave(mp->m_keys);
! 				save_m_str = vim_strsave(mp->m_str);
! 				s = eval_map_expr(save_m_str, NUL);
  				vgetc_busy = save_vgetc_busy;
  			    }
  			    else
***************
*** 2470,2486 ****
  			else
  			{
  			    i = ins_typebuf(s,
! 				    mp->m_noremap != REMAP_YES
! 					    ? mp->m_noremap
! 					    : STRNCMP(s, mp->m_keys,
  							  (size_t)keylen) != 0
  						     ? REMAP_YES : REMAP_SKIP,
! 				0, TRUE, cmd_silent || mp->m_silent);
  #ifdef FEAT_EVAL
! 			    if (mp->m_expr)
  				vim_free(s);
  #endif
  			}
  			if (i == FAIL)
  			{
  			    c = -1;
--- 2493,2517 ----
  			else
  			{
  			    i = ins_typebuf(s,
! 				    save_m_noremap != REMAP_YES
! 					    ? save_m_noremap
! 					    : STRNCMP(s,
! #ifdef FEAT_EVAL
! 					   save_m_keys != NULL ? save_m_keys :
! #endif
! 						      mp->m_keys,
  							  (size_t)keylen) != 0
  						     ? REMAP_YES : REMAP_SKIP,
! 				0, TRUE, cmd_silent || save_m_silent);
  #ifdef FEAT_EVAL
! 			    if (save_m_expr)
  				vim_free(s);
  #endif
  			}
+ #ifdef FEAT_EVAL
+ 			vim_free(save_m_keys);
+ 			vim_free(save_m_str);
+ #endif
  			if (i == FAIL)
  			{
  			    c = -1;
*** ../vim-7.2.346/src/version.c	2010-01-27 16:31:00.000000000 +0100
--- src/version.c	2010-01-27 17:27:32.000000000 +0100
***************
*** 683,684 ****
--- 683,686 ----
  {   /* Add new patch number below this line */
+ /**/
+     347,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
156. You forget your friend's name but not her e-mail address.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///