aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-09-05 13:15:48 -0400
committerScott Prager <splinterofchaos@gmail.com>2014-12-11 20:30:00 -0500
commit3d93e47d9af5722c0e1be1d073090347d6ae28e3 (patch)
tree41f7092e37def49a8aec40405fd4a197c22bdc11 /src/nvim/eval.c
parent171445ef3441a4dbc9958871760e42460ba7404c (diff)
downloadrneovim-3d93e47d9af5722c0e1be1d073090347d6ae28e3.tar.gz
rneovim-3d93e47d9af5722c0e1be1d073090347d6ae28e3.tar.bz2
rneovim-3d93e47d9af5722c0e1be1d073090347d6ae28e3.zip
vim-patch:7.4.249
Problem: Using setreg() with a list of numbers does not work. Solution: Use a separate buffer for numbers. (ZyX) https://code.google.com/p/vim/source/detail?r=v7-4-249
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 2e2871abc5..86ac112212 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -13373,22 +13373,36 @@ static void f_setreg(typval_T *argvars, typval_T *rettv)
if (argvars[1].v_type == VAR_LIST) {
int len = argvars[1].vval.v_list->lv_len;
- char_u **lstval = xmalloc(sizeof(char_u *) * (len + 1));
+ // First half: use for pointers to result lines; second half: use for
+ // pointers to allocated copies.
+ char_u **lstval = xmalloc(sizeof(char_u *) * ((len + 1) * 2));
char_u **curval = lstval;
+ char_u **allocval = lstval + len + 2;
+ char_u **curallocval = allocval;
+ char_u buf[NUMBUFLEN];
for (listitem_T *li = argvars[1].vval.v_list->lv_first;
li != NULL;
li = li->li_next) {
- char_u *strval = get_tv_string_chk(&li->li_tv);
+ char_u *strval = get_tv_string_buf_chk(&li->li_tv, buf);
if (strval == NULL) {
- free(lstval);
- return;
+ goto free_lstval;
+ }
+ if (strval == buf) {
+ // Need to make a copy,
+ // next get_tv_string_buf_chk() will overwrite the string.
+ strval = vim_strsave(buf);
+ *curallocval++ = strval;
}
*curval++ = strval;
}
*curval++ = NULL;
write_reg_contents_lst(regname, lstval, -1, append, yank_type, block_len);
+
+free_lstval:
+ while (curallocval > allocval)
+ free(*--curallocval);
free(lstval);
} else {
char_u *strval = get_tv_string_chk(&argvars[1]);
@@ -16334,6 +16348,7 @@ static char_u *get_tv_string_buf(typval_T *varp, char_u *buf)
return res != NULL ? res : (char_u *)"";
}
+/// Careful: This uses a single, static buffer. YOU CAN ONLY USE IT ONCE!
char_u *get_tv_string_chk(typval_T *varp)
{
static char_u mybuf[NUMBUFLEN];