Mercurial > vim
comparison src/edit.c @ 2177:ea7c2d89b76b v7.2.439
updated for version 7.2.439
Problem: Invalid memory access when doing thesaurus completion and
'infercase' is set.
Solution: Use the minimal length of completed word and replacement.
(Dominique Pelle)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 28 May 2010 21:31:58 +0200 |
parents | 4a4287c09953 |
children | 073ff46fe397 |
comparison
equal
deleted
inserted
replaced
2175:d44112feb815 | 2177:ea7c2d89b76b |
---|---|
2162 { | 2162 { |
2163 char_u *p; | 2163 char_u *p; |
2164 int i, c; | 2164 int i, c; |
2165 int actual_len; /* Take multi-byte characters */ | 2165 int actual_len; /* Take multi-byte characters */ |
2166 int actual_compl_length; /* into account. */ | 2166 int actual_compl_length; /* into account. */ |
2167 int min_len; | |
2167 int *wca; /* Wide character array. */ | 2168 int *wca; /* Wide character array. */ |
2168 int has_lower = FALSE; | 2169 int has_lower = FALSE; |
2169 int was_letter = FALSE; | 2170 int was_letter = FALSE; |
2170 | 2171 |
2171 if (p_ic && curbuf->b_p_inf && len > 0) | 2172 if (p_ic && curbuf->b_p_inf && len > 0) |
2201 } | 2202 } |
2202 } | 2203 } |
2203 else | 2204 else |
2204 #endif | 2205 #endif |
2205 actual_compl_length = compl_length; | 2206 actual_compl_length = compl_length; |
2207 | |
2208 /* "actual_len" may be smaller than "actual_compl_length" when using | |
2209 * thesaurus, only use the minimum when comparing. */ | |
2210 min_len = actual_len < actual_compl_length | |
2211 ? actual_len : actual_compl_length; | |
2206 | 2212 |
2207 /* Allocate wide character array for the completion and fill it. */ | 2213 /* Allocate wide character array for the completion and fill it. */ |
2208 wca = (int *)alloc((unsigned)(actual_len * sizeof(int))); | 2214 wca = (int *)alloc((unsigned)(actual_len * sizeof(int))); |
2209 if (wca != NULL) | 2215 if (wca != NULL) |
2210 { | 2216 { |
2217 #endif | 2223 #endif |
2218 wca[i] = *(p++); | 2224 wca[i] = *(p++); |
2219 | 2225 |
2220 /* Rule 1: Were any chars converted to lower? */ | 2226 /* Rule 1: Were any chars converted to lower? */ |
2221 p = compl_orig_text; | 2227 p = compl_orig_text; |
2222 for (i = 0; i < actual_compl_length; ++i) | 2228 for (i = 0; i < min_len; ++i) |
2223 { | 2229 { |
2224 #ifdef FEAT_MBYTE | 2230 #ifdef FEAT_MBYTE |
2225 if (has_mbyte) | 2231 if (has_mbyte) |
2226 c = mb_ptr2char_adv(&p); | 2232 c = mb_ptr2char_adv(&p); |
2227 else | 2233 else |
2245 * upper case. | 2251 * upper case. |
2246 */ | 2252 */ |
2247 if (!has_lower) | 2253 if (!has_lower) |
2248 { | 2254 { |
2249 p = compl_orig_text; | 2255 p = compl_orig_text; |
2250 for (i = 0; i < actual_compl_length; ++i) | 2256 for (i = 0; i < min_len; ++i) |
2251 { | 2257 { |
2252 #ifdef FEAT_MBYTE | 2258 #ifdef FEAT_MBYTE |
2253 if (has_mbyte) | 2259 if (has_mbyte) |
2254 c = mb_ptr2char_adv(&p); | 2260 c = mb_ptr2char_adv(&p); |
2255 else | 2261 else |
2266 } | 2272 } |
2267 } | 2273 } |
2268 | 2274 |
2269 /* Copy the original case of the part we typed. */ | 2275 /* Copy the original case of the part we typed. */ |
2270 p = compl_orig_text; | 2276 p = compl_orig_text; |
2271 for (i = 0; i < actual_compl_length; ++i) | 2277 for (i = 0; i < min_len; ++i) |
2272 { | 2278 { |
2273 #ifdef FEAT_MBYTE | 2279 #ifdef FEAT_MBYTE |
2274 if (has_mbyte) | 2280 if (has_mbyte) |
2275 c = mb_ptr2char_adv(&p); | 2281 c = mb_ptr2char_adv(&p); |
2276 else | 2282 else |