diff options
author | ZyX <kp-pav@yandex.ru> | 2018-01-03 00:00:16 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2018-01-14 01:33:16 +0300 |
commit | 9ea1752d60589e8fc5e7184144bc6d1c1b9f16a3 (patch) | |
tree | 8d7fd11beeb2a300bd21f997e3fdca5b4f29382e /src/nvim/ops.c | |
parent | 9ddeb6e187e6ef6045bf037e4225dc46c8efb693 (diff) | |
download | rneovim-9ea1752d60589e8fc5e7184144bc6d1c1b9f16a3.tar.gz rneovim-9ea1752d60589e8fc5e7184144bc6d1c1b9f16a3.tar.bz2 rneovim-9ea1752d60589e8fc5e7184144bc6d1c1b9f16a3.zip |
*: Provide list length when allocating lists
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a5e131190d..b606f10b88 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2564,7 +2564,7 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) dict_T *dict = get_vim_var_dict(VV_EVENT); // the yanked text - list_T *list = tv_list_alloc(); + list_T *const list = tv_list_alloc((ptrdiff_t)reg->y_size); for (size_t i = 0; i < reg->y_size; i++) { tv_list_append_string(list, (const char *)reg->y_array[i], -1); } @@ -4854,7 +4854,7 @@ static void *get_reg_wrap_one_line(char_u *s, int flags) if (!(flags & kGRegList)) { return s; } - list_T *const list = tv_list_alloc(); + list_T *const list = tv_list_alloc(1); tv_list_append_allocated_string(list, (char *)s); return list; } @@ -4904,7 +4904,7 @@ void *get_reg_contents(int regname, int flags) return NULL; if (flags & kGRegList) { - list_T *list = tv_list_alloc(); + list_T *const list = tv_list_alloc((ptrdiff_t)reg->y_size); for (size_t i = 0; i < reg->y_size; i++) { tv_list_append_string(list, (const char *)reg->y_array[i], -1); } @@ -5593,7 +5593,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) } free_register(reg); - list_T *const args = tv_list_alloc(); + list_T *const args = tv_list_alloc(1); const char regname = (char)name; tv_list_append_string(args, ®name, 1); @@ -5712,15 +5712,13 @@ static void set_clipboard(int name, yankreg_T *reg) return; } - list_T *lines = tv_list_alloc(); + list_T *const lines = tv_list_alloc( + (ptrdiff_t)reg->y_size + (reg->y_type != kMTCharWise)); for (size_t i = 0; i < reg->y_size; i++) { tv_list_append_string(lines, (const char *)reg->y_array[i], -1); } - list_T *args = tv_list_alloc(); - tv_list_append_list(args, lines); - char regtype; switch (reg->y_type) { case kMTLineWise: { @@ -5741,10 +5739,11 @@ static void set_clipboard(int name, yankreg_T *reg) assert(false); } } - tv_list_append_string(args, ®type, 1); - const char regname = (char)name; - tv_list_append_string(args, ®name, 1); + list_T *args = tv_list_alloc(3); + tv_list_append_list(args, lines); + tv_list_append_string(args, ®type, 1); + tv_list_append_string(args, ((char[]) { (char)name }), 1); (void)eval_call_provider("clipboard", "set", args); } |