]>
Commit | Line | Data |
---|---|---|
b02c59fe ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.2.016 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.2.016 | |
11 | Problem: The pattern being completed may be in freed memory when the | |
12 | command line is being reallocated. (Dominique Pelle) | |
13 | Solution: Keep a pointer to the expand_T in the command line structure. | |
14 | Don't use <S-Tab> as CTRL-P when there are no results. Clear the | |
15 | completion when using a command line from the history. | |
16 | Files: src/ex_getln.c | |
17 | ||
18 | ||
19 | *** ../vim-7.2.015/src/ex_getln.c Fri Aug 8 12:58:59 2008 | |
20 | --- src/ex_getln.c Wed Sep 10 22:43:41 2008 | |
21 | *************** | |
22 | *** 31,36 **** | |
23 | --- 31,38 ---- | |
24 | int cmdattr; /* attributes for prompt */ | |
25 | int overstrike; /* Typing mode on the command line. Shared by | |
26 | getcmdline() and put_on_cmdline(). */ | |
27 | + expand_T *xpc; /* struct being used for expansion, xp_pattern | |
28 | + may point into cmdbuff */ | |
29 | int xp_context; /* type of expansion */ | |
30 | # ifdef FEAT_EVAL | |
31 | char_u *xp_arg; /* user-defined expansion arg */ | |
32 | *************** | |
33 | *** 38,44 **** | |
34 | # endif | |
35 | }; | |
36 | ||
37 | ! static struct cmdline_info ccline; /* current cmdline_info */ | |
38 | ||
39 | static int cmd_showtail; /* Only show path tail in lists ? */ | |
40 | ||
41 | --- 40,50 ---- | |
42 | # endif | |
43 | }; | |
44 | ||
45 | ! /* The current cmdline_info. It is initialized in getcmdline() and after that | |
46 | ! * used by other functions. When invoking getcmdline() recursively it needs | |
47 | ! * to be saved with save_cmdline() and restored with restore_cmdline(). | |
48 | ! * TODO: make it local to getcmdline() and pass it around. */ | |
49 | ! static struct cmdline_info ccline; | |
50 | ||
51 | static int cmd_showtail; /* Only show path tail in lists ? */ | |
52 | ||
53 | *************** | |
54 | *** 238,243 **** | |
55 | --- 244,250 ---- | |
56 | } | |
57 | ||
58 | ExpandInit(&xpc); | |
59 | + ccline.xpc = &xpc; | |
60 | ||
61 | #ifdef FEAT_RIGHTLEFT | |
62 | if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | |
63 | *************** | |
64 | *** 408,416 **** | |
65 | #endif | |
66 | ||
67 | /* | |
68 | ! * <S-Tab> works like CTRL-P (unless 'wc' is <S-Tab>). | |
69 | */ | |
70 | ! if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles != -1) | |
71 | c = Ctrl_P; | |
72 | ||
73 | #ifdef FEAT_WILDMENU | |
74 | --- 415,424 ---- | |
75 | #endif | |
76 | ||
77 | /* | |
78 | ! * When there are matching completions to select <S-Tab> works like | |
79 | ! * CTRL-P (unless 'wc' is <S-Tab>). | |
80 | */ | |
81 | ! if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0) | |
82 | c = Ctrl_P; | |
83 | ||
84 | #ifdef FEAT_WILDMENU | |
85 | *************** | |
86 | *** 1513,1518 **** | |
87 | --- 1521,1527 ---- | |
88 | int old_firstc; | |
89 | ||
90 | vim_free(ccline.cmdbuff); | |
91 | + xpc.xp_context = EXPAND_NOTHING; | |
92 | if (hiscnt == hislen) | |
93 | p = lookfor; /* back to the old one */ | |
94 | else | |
95 | *************** | |
96 | *** 1839,1844 **** | |
97 | --- 1848,1854 ---- | |
98 | #endif | |
99 | ||
100 | ExpandCleanup(&xpc); | |
101 | + ccline.xpc = NULL; | |
102 | ||
103 | #ifdef FEAT_SEARCH_EXTRA | |
104 | if (did_incsearch) | |
105 | *************** | |
106 | *** 2508,2513 **** | |
107 | --- 2518,2537 ---- | |
108 | } | |
109 | mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen + 1); | |
110 | vim_free(p); | |
111 | + | |
112 | + if (ccline.xpc != NULL | |
113 | + && ccline.xpc->xp_pattern != NULL | |
114 | + && ccline.xpc->xp_context != EXPAND_NOTHING | |
115 | + && ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL) | |
116 | + { | |
117 | + int i = ccline.xpc->xp_pattern - p; | |
118 | + | |
119 | + /* If xp_pattern points inside the old cmdbuff it needs to be adjusted | |
120 | + * to point into the newly allocated memory. */ | |
121 | + if (i >= 0 && i <= ccline.cmdlen) | |
122 | + ccline.xpc->xp_pattern = ccline.cmdbuff + i; | |
123 | + } | |
124 | + | |
125 | return OK; | |
126 | } | |
127 | ||
128 | *************** | |
129 | *** 2875,2880 **** | |
130 | --- 2899,2905 ---- | |
131 | prev_ccline = ccline; | |
132 | ccline.cmdbuff = NULL; | |
133 | ccline.cmdprompt = NULL; | |
134 | + ccline.xpc = NULL; | |
135 | } | |
136 | ||
137 | /* | |
138 | *************** | |
139 | *** 3582,3587 **** | |
140 | --- 3607,3613 ---- | |
141 | ExpandInit(xp) | |
142 | expand_T *xp; | |
143 | { | |
144 | + xp->xp_pattern = NULL; | |
145 | xp->xp_backslash = XP_BS_NONE; | |
146 | #ifndef BACKSLASH_IN_FILENAME | |
147 | xp->xp_shell = FALSE; | |
148 | *** ../vim-7.2.015/src/version.c Wed Sep 10 18:25:18 2008 | |
149 | --- src/version.c Sun Sep 14 14:38:47 2008 | |
150 | *************** | |
151 | *** 678,679 **** | |
152 | --- 678,681 ---- | |
153 | { /* Add new patch number below this line */ | |
154 | + /**/ | |
155 | + 16, | |
156 | /**/ | |
157 | ||
158 | -- | |
159 | hundred-and-one symptoms of being an internet addict: | |
160 | 53. To find out what time it is, you send yourself an e-mail and check the | |
161 | "Date:" field. | |
162 | ||
163 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
164 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
165 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
166 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |