4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Crash in ":let" when redirecting to a variable that's being
12 displayed. (Thomas Link)
13 Solution: When redirecting to a variable only do the assignment when
14 stopping redirection to avoid that setting the variable causes a
15 freed string to be accessed.
19 *** ../vim-7.0.182/src/eval.c Tue Dec 5 10:33:57 2006
20 --- src/eval.c Sun Jan 14 14:20:49 2007
26 static lval_T *redir_lval = NULL;
27 + static garray_T redir_ga; /* only valid when redir_lval is not NULL */
28 static char_u *redir_endp = NULL;
29 static char_u *redir_varname = NULL;
37 + /* The output is stored in growarray "redir_ga" until redirection ends. */
38 + ga_init2(&redir_ga, (int)sizeof(char), 500);
40 /* Parse the variable name (can be a dict or list entry). */
41 redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, FALSE,
48 ! * Append "value[len]" to the variable set by var_redir_start().
51 ! var_redir_str(value, len)
60 if (redir_lval == NULL)
64 ! /* Append the entire string */
65 ! val = vim_strsave(value);
67 ! /* Append only the specified number of characters */
68 ! val = vim_strnsave(value, len);
72 ! tv.v_type = VAR_STRING;
73 ! tv.vval.v_string = val;
75 ! save_emsg = did_emsg;
77 ! set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
79 ! did_emsg |= save_emsg;
83 - vim_free(tv.vval.v_string);
91 ! * Append "value[value_len]" to the variable set by var_redir_start().
92 ! * The actual appending is postponed until redirection ends, because the value
93 ! * appended may in fact be the string we write to, changing it may cause freed
94 ! * memory to be used:
100 ! var_redir_str(value, value_len)
106 if (redir_lval == NULL)
109 ! if (value_len == -1)
110 ! len = STRLEN(value); /* Append the entire string */
112 ! len = value_len; /* Append only "value_len" characters */
114 ! if (ga_grow(&redir_ga, (int)len) == OK)
116 ! mch_memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len);
117 ! redir_ga.ga_len += len;
132 if (redir_lval != NULL)
134 + /* Append the trailing NUL. */
135 + ga_append(&redir_ga, NUL);
137 + /* Assign the text to the variable. */
138 + tv.v_type = VAR_STRING;
139 + tv.vval.v_string = redir_ga.ga_data;
140 + set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
141 + vim_free(tv.vval.v_string);
143 clear_lval(redir_lval);
144 vim_free(redir_lval);
146 *** ../vim-7.0.182/src/version.c Tue Jan 9 20:29:55 2007
147 --- src/version.c Sun Jan 14 15:23:23 2007
151 { /* Add new patch number below this line */
157 How To Keep A Healthy Level Of Insanity:
158 16. Have your coworkers address you by your wrestling name, Rock Hard Kim.
160 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
161 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
162 \\\ download, build and distribute -- http://www.A-A-P.org ///
163 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///