We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d23089a commit 512933aCopy full SHA for 512933a
4 files changed
src/eval.c
@@ -16827,31 +16827,46 @@ f_setreg(argvars, rettv)
16827
if (argvars[1].v_type == VAR_LIST)
16828
{
16829
char_u **lstval;
16830
+ char_u **allocval;
16831
+ char_u buf[NUMBUFLEN];
16832
char_u **curval;
16833
+ char_u **curallocval;
16834
int len = argvars[1].vval.v_list->lv_len;
16835
listitem_T *li;
16836
- lstval = (char_u **)alloc(sizeof(char_u *) * (len + 1));
16837
+ /* First half: use for pointers to result lines; second half: use for
16838
+ * pointers to allocated copies. */
16839
+ lstval = (char_u **)alloc(sizeof(char_u *) * ((len + 1) * 2));
16840
if (lstval == NULL)
16841
return;
16842
curval = lstval;
16843
+ allocval = lstval + len + 2;
16844
+ curallocval = allocval;
16845
16846
for (li = argvars[1].vval.v_list->lv_first; li != NULL;
16847
li = li->li_next)
16848
- /* TODO: this may use a static buffer several times. */
- strval = get_tv_string_chk(&li->li_tv);
16849
+ strval = get_tv_string_buf_chk(&li->li_tv, buf);
16850
if (strval == NULL)
16851
+ goto free_lstval;
16852
+ if (strval == buf)
16853
- vim_free(lstval);
- return;
16854
+ /* Need to make a copy, next get_tv_string_buf_chk() will
16855
+ * overwrite the string. */
16856
+ strval = vim_strsave(buf);
16857
+ if (strval == NULL)
16858
16859
+ *curallocval++ = strval;
16860
}
16861
*curval++ = strval;
16862
16863
*curval++ = NULL;
16864
16865
write_reg_contents_lst(regname, lstval, -1,
16866
append, yank_type, block_len);
16867
+free_lstval:
16868
+ while (curallocval > allocval)
16869
+ vim_free(*--curallocval);
16870
vim_free(lstval);
16871
16872
else
@@ -20453,6 +20468,9 @@ get_tv_string_buf(varp, buf)
20453
20468
return res != NULL ? res : (char_u *)"";
20454
20469
20455
20470
20471
+/*
20472
+ * Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
20473
+ */
20456
20474
char_u *
20457
20475
get_tv_string_chk(varp)
20458
20476
typval_T *varp;
src/testdir/test_eval.in
@@ -90,6 +90,8 @@ call SetReg('a', ['abcA3'], 'c')
90
call SetReg('b', ['abcB3'], 'l')
91
call SetReg('c', ['abcC3'], 'b')
92
call SetReg('d', ['abcD3'])
93
+call SetReg('e', [1, 2, 'abc', 3])
94
+call SetReg('f', [1, 2, 3])
95
96
$put ='{{{1 Appending lists with setreg()'
97
call SetReg('A', ['abcA3c'], 'c')
@@ -128,8 +130,8 @@ call ErrExe('call setreg(1, 2, 3, 4)')
128
130
call ErrExe('call setreg([], 2)')
129
131
call ErrExe('call setreg(1, {})')
132
call ErrExe('call setreg(1, 2, [])')
-call ErrExe('call setreg("/", [1, 2])')
-call ErrExe('call setreg("=", [1, 2])')
133
+call ErrExe('call setreg("/", ["1", "2"])')
134
+call ErrExe('call setreg("=", ["1", "2"])')
135
call ErrExe('call setreg(1, ["", "", [], ""])')
136
endfun
137
:"
src/testdir/test_eval.ok
271 Bytes
src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
734
735
static int included_patches[] =
736
{ /* Add new patch number below this line */
737
+/**/
738
+ 249,
739
/**/
740
248,
741
0 commit comments