summaryrefslogtreecommitdiffstats
path: root/vim/vim-7.2/7.2.080
blob: 399f9e1c37e28b36896390dcb46d9bc97edb0d89 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
To: vim-dev@vim.org
Subject: Patch 7.2.080
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.080
Problem:    When typing a composing character just after starting completion
	    may access memory before its allocation point. (Dominique Pelle)
Solution:   Don't delete before the completion start column.  Add extra checks
	    for the offset not being negative.
Files:	    src/edit.c


*** ../vim-7.2.079/src/edit.c	Wed Aug  6 18:56:55 2008
--- src/edit.c	Tue Jan 13 12:05:57 2009
***************
*** 147,152 ****
--- 147,153 ----
  static int  ins_compl_bs __ARGS((void));
  static void ins_compl_new_leader __ARGS((void));
  static void ins_compl_addleader __ARGS((int c));
+ static int ins_compl_len __ARGS((void));
  static void ins_compl_restart __ARGS((void));
  static void ins_compl_set_original_text __ARGS((char_u *str));
  static void ins_compl_addfrommatch __ARGS((void));
***************
*** 197,203 ****
  static void mb_replace_pop_ins __ARGS((int cc));
  #endif
  static void replace_flush __ARGS((void));
! static void replace_do_bs __ARGS((void));
  #ifdef FEAT_CINDENT
  static int cindent_on __ARGS((void));
  #endif
--- 198,205 ----
  static void mb_replace_pop_ins __ARGS((int cc));
  #endif
  static void replace_flush __ARGS((void));
! static void replace_do_bs __ARGS((int limit_col));
! static int del_char_after_col __ARGS((int limit_col));
  #ifdef FEAT_CINDENT
  static int cindent_on __ARGS((void));
  #endif
***************
*** 1933,1938 ****
--- 1935,1942 ----
  /*
   * Backspace the cursor until the given column.  Handles REPLACE and VREPLACE
   * modes correctly.  May also be used when not in insert mode at all.
+  * Will attempt not to go before "col" even when there is a composing
+  * character.
   */
      void
  backspace_until_column(col)
***************
*** 1942,1954 ****
      {
  	curwin->w_cursor.col--;
  	if (State & REPLACE_FLAG)
! 	    replace_do_bs();
! 	else
! 	    (void)del_char(FALSE);
      }
  }
  #endif
  
  #if defined(FEAT_INS_EXPAND) || defined(PROTO)
  /*
   * CTRL-X pressed in Insert mode.
--- 1946,1994 ----
      {
  	curwin->w_cursor.col--;
  	if (State & REPLACE_FLAG)
! 	    replace_do_bs(col);
! 	else if (!del_char_after_col(col))
! 	    break;
      }
  }
  #endif
  
+ /*
+  * Like del_char(), but make sure not to go before column "limit_col".
+  * Only matters when there are composing characters.
+  * Return TRUE when something was deleted.
+  */
+    static int
+ del_char_after_col(limit_col)
+     int limit_col;
+ {
+ #ifdef FEAT_MBYTE
+     if (enc_utf8 && limit_col >= 0)
+     {
+ 	int ecol = curwin->w_cursor.col + 1;
+ 
+ 	/* Make sure the cursor is at the start of a character, but
+ 	 * skip forward again when going too far back because of a
+ 	 * composing character. */
+ 	mb_adjust_cursor();
+ 	while (curwin->w_cursor.col < limit_col)
+ 	{
+ 	    int l = utf_ptr2len(ml_get_cursor());
+ 
+ 	    if (l == 0)  /* end of line */
+ 		break;
+ 	    curwin->w_cursor.col += l;
+ 	}
+ 	if (*ml_get_cursor() == NUL || curwin->w_cursor.col == ecol)
+ 	    return FALSE;
+ 	del_bytes((long)(ecol - curwin->w_cursor.col), FALSE, TRUE);
+     }
+     else
+ #endif
+ 	(void)del_char(FALSE);
+     return TRUE;
+ }
+ 
  #if defined(FEAT_INS_EXPAND) || defined(PROTO)
  /*
   * CTRL-X pressed in Insert mode.
***************
*** 2418,2424 ****
  	{
  	    had_match = (curwin->w_cursor.col > compl_col);
  	    ins_compl_delete();
! 	    ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  	    ins_redraw(FALSE);
  
  	    /* When the match isn't there (to avoid matching itself) remove it
--- 2458,2464 ----
  	{
  	    had_match = (curwin->w_cursor.col > compl_col);
  	    ins_compl_delete();
! 	    ins_bytes(compl_leader + ins_compl_len());
  	    ins_redraw(FALSE);
  
  	    /* When the match isn't there (to avoid matching itself) remove it
***************
*** 2470,2476 ****
  	    *p = NUL;
  	    had_match = (curwin->w_cursor.col > compl_col);
  	    ins_compl_delete();
! 	    ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  	    ins_redraw(FALSE);
  
  	    /* When the match isn't there (to avoid matching itself) remove it
--- 2510,2516 ----
  	    *p = NUL;
  	    had_match = (curwin->w_cursor.col > compl_col);
  	    ins_compl_delete();
! 	    ins_bytes(compl_leader + ins_compl_len());
  	    ins_redraw(FALSE);
  
  	    /* When the match isn't there (to avoid matching itself) remove it
***************
*** 3209,3215 ****
  {
      ins_compl_del_pum();
      ins_compl_delete();
!     ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
      compl_used_match = FALSE;
  
      if (compl_started)
--- 3249,3255 ----
  {
      ins_compl_del_pum();
      ins_compl_delete();
!     ins_bytes(compl_leader + ins_compl_len());
      compl_used_match = FALSE;
  
      if (compl_started)
***************
*** 3264,3269 ****
--- 3304,3323 ----
  }
  
  /*
+  * Return the length of the completion, from the completion start column to
+  * the cursor column.  Making sure it never goes below zero.
+  */
+     static int
+ ins_compl_len()
+ {
+     int off = curwin->w_cursor.col - compl_col;
+ 
+     if (off < 0)
+ 	return 0;
+     return off;
+ }
+ 
+ /*
   * Append one character to the match leader.  May reduce the number of
   * matches.
   */
***************
*** 3621,3630 ****
  	    {
  		ins_compl_delete();
  		if (compl_leader != NULL)
! 		    ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
  		else if (compl_first_match != NULL)
! 		    ins_bytes(compl_orig_text
! 					  + curwin->w_cursor.col - compl_col);
  		retval = TRUE;
  	    }
  
--- 3675,3683 ----
  	    {
  		ins_compl_delete();
  		if (compl_leader != NULL)
! 		    ins_bytes(compl_leader + ins_compl_len());
  		else if (compl_first_match != NULL)
! 		    ins_bytes(compl_orig_text + ins_compl_len());
  		retval = TRUE;
  	    }
  
***************
*** 4256,4262 ****
      static void
  ins_compl_insert()
  {
!     ins_bytes(compl_shown_match->cp_str + curwin->w_cursor.col - compl_col);
      if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
  	compl_used_match = FALSE;
      else
--- 4309,4315 ----
      static void
  ins_compl_insert()
  {
!     ins_bytes(compl_shown_match->cp_str + ins_compl_len());
      if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
  	compl_used_match = FALSE;
      else
***************
*** 4425,4431 ****
  	if (!compl_get_longest || compl_used_match)
  	    ins_compl_insert();
  	else
! 	    ins_bytes(compl_leader + curwin->w_cursor.col - compl_col);
      }
      else
  	compl_used_match = FALSE;
--- 4478,4484 ----
  	if (!compl_get_longest || compl_used_match)
  	    ins_compl_insert();
  	else
! 	    ins_bytes(compl_leader + ins_compl_len());
      }
      else
  	compl_used_match = FALSE;
***************
*** 7123,7131 ****
   * cc == 0: character was inserted, delete it
   * cc > 0: character was replaced, put cc (first byte of original char) back
   * and check for more characters to be put back
   */
      static void
! replace_do_bs()
  {
      int		cc;
  #ifdef FEAT_VREPLACE
--- 7176,7187 ----
   * cc == 0: character was inserted, delete it
   * cc > 0: character was replaced, put cc (first byte of original char) back
   * and check for more characters to be put back
+  * When "limit_col" is >= 0, don't delete before this column.  Matters when
+  * using composing characters, use del_char_after_col() instead of del_char().
   */
      static void
! replace_do_bs(limit_col)
!     int		limit_col;
  {
      int		cc;
  #ifdef FEAT_VREPLACE
***************
*** 7153,7159 ****
  #ifdef FEAT_MBYTE
  	if (has_mbyte)
  	{
! 	    del_char(FALSE);
  # ifdef FEAT_VREPLACE
  	    if (State & VREPLACE_FLAG)
  		orig_len = (int)STRLEN(ml_get_cursor());
--- 7209,7215 ----
  #ifdef FEAT_MBYTE
  	if (has_mbyte)
  	{
! 	    (void)del_char_after_col(limit_col);
  # ifdef FEAT_VREPLACE
  	    if (State & VREPLACE_FLAG)
  		orig_len = (int)STRLEN(ml_get_cursor());
***************
*** 7203,7209 ****
  	changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
      }
      else if (cc == 0)
! 	(void)del_char(FALSE);
  }
  
  #ifdef FEAT_CINDENT
--- 7259,7265 ----
  	changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
      }
      else if (cc == 0)
! 	(void)del_char_after_col(limit_col);
  }
  
  #ifdef FEAT_CINDENT
***************
*** 8239,8245 ****
  	 * Replace mode */
  	if (curwin->w_cursor.lnum != Insstart.lnum
  		|| curwin->w_cursor.col >= Insstart.col)
! 	    replace_do_bs();
      }
      else
  	(void)del_char(FALSE);
--- 8295,8301 ----
  	 * Replace mode */
  	if (curwin->w_cursor.lnum != Insstart.lnum
  		|| curwin->w_cursor.col >= Insstart.col)
! 	    replace_do_bs(-1);
      }
      else
  	(void)del_char(FALSE);
***************
*** 8556,8562 ****
  		break;
  	    }
  	    if (State & REPLACE_FLAG)
! 		replace_do_bs();
  	    else
  	    {
  #ifdef FEAT_MBYTE
--- 8612,8618 ----
  		break;
  	    }
  	    if (State & REPLACE_FLAG)
! 		replace_do_bs(-1);
  	    else
  	    {
  #ifdef FEAT_MBYTE
*** ../vim-7.2.079/src/version.c	Tue Jan  6 16:13:42 2009
--- src/version.c	Tue Jan 13 12:25:29 2009
***************
*** 678,679 ****
--- 678,681 ----
  {   /* Add new patch number below this line */
+ /**/
+     80,
  /**/

-- 
At some point in the project somebody will start whining about the need to
determine the project "requirements".  This involves interviewing people who
don't know what they want but, curiously, know exactly when they need it.
				(Scott Adams - The Dilbert principle)

 /// 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    ///