• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisão4a4b16c67c62174b3b66848a32f4e5554b9cf6c0 (tree)
Hora2007-01-14 23:28:34
Autorvimboss
Commitervimboss

Mensagem de Log

updated for version 7.0-183

Mudança Sumário

Diff

diff -r e6d25347de2c -r 4a4b16c67c62 src/eval.c
--- a/src/eval.c Tue Jan 09 19:23:12 2007 +0000
+++ b/src/eval.c Sun Jan 14 14:28:34 2007 +0000
@@ -898,6 +898,7 @@
898898 }
899899
900900 static lval_T *redir_lval = NULL;
901+static garray_T redir_ga; /* only valid when redir_lval is not NULL */
901902 static char_u *redir_endp = NULL;
902903 static char_u *redir_varname = NULL;
903904
@@ -932,6 +933,9 @@
932933 return FAIL;
933934 }
934935
936+ /* The output is stored in growarray "redir_ga" until redirection ends. */
937+ ga_init2(&redir_ga, (int)sizeof(char), 500);
938+
935939 /* Parse the variable name (can be a dict or list entry). */
936940 redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, FALSE,
937941 FNE_CHECK_START);
@@ -974,42 +978,36 @@
974978 }
975979
976980 /*
977- * Append "value[len]" to the variable set by var_redir_start().
981+ * Append "value[value_len]" to the variable set by var_redir_start().
982+ * The actual appending is postponed until redirection ends, because the value
983+ * appended may in fact be the string we write to, changing it may cause freed
984+ * memory to be used:
985+ * :redir => foo
986+ * :let foo
987+ * :redir END
978988 */
979989 void
980-var_redir_str(value, len)
990+var_redir_str(value, value_len)
981991 char_u *value;
982- int len;
983-{
984- char_u *val;
985- typval_T tv;
986- int save_emsg;
987- int err;
992+ int value_len;
993+{
994+ size_t len;
988995
989996 if (redir_lval == NULL)
990997 return;
991998
992- if (len == -1)
993- /* Append the entire string */
994- val = vim_strsave(value);
995- else
996- /* Append only the specified number of characters */
997- val = vim_strnsave(value, len);
998- if (val == NULL)
999- return;
1000-
1001- tv.v_type = VAR_STRING;
1002- tv.vval.v_string = val;
1003-
1004- save_emsg = did_emsg;
1005- did_emsg = FALSE;
1006- set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
1007- err = did_emsg;
1008- did_emsg |= save_emsg;
1009- if (err)
999+ if (value_len == -1)
1000+ len = STRLEN(value); /* Append the entire string */
1001+ else
1002+ len = value_len; /* Append only "value_len" characters */
1003+
1004+ if (ga_grow(&redir_ga, (int)len) == OK)
1005+ {
1006+ mch_memmove((char *)redir_ga.ga_data + redir_ga.ga_len, value, len);
1007+ redir_ga.ga_len += len;
1008+ }
1009+ else
10101010 var_redir_stop();
1011-
1012- vim_free(tv.vval.v_string);
10131011 }
10141012
10151013 /*
@@ -1018,8 +1016,19 @@
10181016 void
10191017 var_redir_stop()
10201018 {
1019+ typval_T tv;
1020+
10211021 if (redir_lval != NULL)
10221022 {
1023+ /* Append the trailing NUL. */
1024+ ga_append(&redir_ga, NUL);
1025+
1026+ /* Assign the text to the variable. */
1027+ tv.v_type = VAR_STRING;
1028+ tv.vval.v_string = redir_ga.ga_data;
1029+ set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
1030+ vim_free(tv.vval.v_string);
1031+
10231032 clear_lval(redir_lval);
10241033 vim_free(redir_lval);
10251034 redir_lval = NULL;
diff -r e6d25347de2c -r 4a4b16c67c62 src/version.c
--- a/src/version.c Tue Jan 09 19:23:12 2007 +0000
+++ b/src/version.c Sun Jan 14 14:28:34 2007 +0000
@@ -667,6 +667,8 @@
667667 static int included_patches[] =
668668 { /* Add new patch number below this line */
669669 /**/
670+ 183,
671+/**/
670672 182,
671673 /**/
672674 181,
Show on old repository browser