Skip to content

Commit 512933a

Browse files
committed
updated for version 7.4.249
Problem: Using setreg() with a list of numbers does not work. Solution: Use a separate buffer for numbers. (ZyX)
1 parent d23089a commit 512933a

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/eval.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16827,31 +16827,46 @@ f_setreg(argvars, rettv)
1682716827
if (argvars[1].v_type == VAR_LIST)
1682816828
{
1682916829
char_u **lstval;
16830+
char_u **allocval;
16831+
char_u buf[NUMBUFLEN];
1683016832
char_u **curval;
16833+
char_u **curallocval;
1683116834
int len = argvars[1].vval.v_list->lv_len;
1683216835
listitem_T *li;
1683316836

16834-
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));
1683516840
if (lstval == NULL)
1683616841
return;
1683716842
curval = lstval;
16843+
allocval = lstval + len + 2;
16844+
curallocval = allocval;
1683816845

1683916846
for (li = argvars[1].vval.v_list->lv_first; li != NULL;
1684016847
li = li->li_next)
1684116848
{
16842-
/* TODO: this may use a static buffer several times. */
16843-
strval = get_tv_string_chk(&li->li_tv);
16849+
strval = get_tv_string_buf_chk(&li->li_tv, buf);
1684416850
if (strval == NULL)
16851+
goto free_lstval;
16852+
if (strval == buf)
1684516853
{
16846-
vim_free(lstval);
16847-
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+
goto free_lstval;
16859+
*curallocval++ = strval;
1684816860
}
1684916861
*curval++ = strval;
1685016862
}
1685116863
*curval++ = NULL;
1685216864

1685316865
write_reg_contents_lst(regname, lstval, -1,
1685416866
append, yank_type, block_len);
16867+
free_lstval:
16868+
while (curallocval > allocval)
16869+
vim_free(*--curallocval);
1685516870
vim_free(lstval);
1685616871
}
1685716872
else
@@ -20453,6 +20468,9 @@ get_tv_string_buf(varp, buf)
2045320468
return res != NULL ? res : (char_u *)"";
2045420469
}
2045520470

20471+
/*
20472+
* Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
20473+
*/
2045620474
char_u *
2045720475
get_tv_string_chk(varp)
2045820476
typval_T *varp;

src/testdir/test_eval.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ call SetReg('a', ['abcA3'], 'c')
9090
call SetReg('b', ['abcB3'], 'l')
9191
call SetReg('c', ['abcC3'], 'b')
9292
call SetReg('d', ['abcD3'])
93+
call SetReg('e', [1, 2, 'abc', 3])
94+
call SetReg('f', [1, 2, 3])
9395

9496
$put ='{{{1 Appending lists with setreg()'
9597
call SetReg('A', ['abcA3c'], 'c')
@@ -128,8 +130,8 @@ call ErrExe('call setreg(1, 2, 3, 4)')
128130
call ErrExe('call setreg([], 2)')
129131
call ErrExe('call setreg(1, {})')
130132
call ErrExe('call setreg(1, 2, [])')
131-
call ErrExe('call setreg("/", [1, 2])')
132-
call ErrExe('call setreg("=", [1, 2])')
133+
call ErrExe('call setreg("/", ["1", "2"])')
134+
call ErrExe('call setreg("=", ["1", "2"])')
133135
call ErrExe('call setreg(1, ["", "", [], ""])')
134136
endfun
135137
:"

src/testdir/test_eval.ok

271 Bytes
Binary file not shown.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
249,
737739
/**/
738740
248,
739741
/**/

0 commit comments

Comments
 (0)