From ab860cb5f6c749b937e0986167702a36e45000ca Mon Sep 17 00:00:00 2001 From: erw7 Date: Mon, 2 Dec 2019 19:09:30 +0900 Subject: dictwatcher: fix use-after-free #11495 fixes #11494 --- src/nvim/eval/typval.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 106b8f6eed..72ee45a03a 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1200,6 +1200,7 @@ void tv_dict_watcher_notify(dict_T *const dict, const char *const key, typval_T rettv; + dict->dv_refcount++; QUEUE *w; QUEUE_FOREACH(w, &dict->watchers) { DictWatcher *watcher = tv_dict_watcher_node_data(w); @@ -1211,6 +1212,7 @@ void tv_dict_watcher_notify(dict_T *const dict, const char *const key, tv_clear(&rettv); } } + tv_dict_unref(dict); for (size_t i = 1; i < ARRAY_SIZE(argv); i++) { tv_clear(argv + i); -- cgit From 80ebfc304e295cdb1bed3d0f2781d7884933719a Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 22 Dec 2019 18:45:17 -0500 Subject: vim-patch:8.2.0030: "gF" does not work on output of "verbose command" Problem: "gF" does not work on output of "verbose command". Solution: Recognize " line " and translations. (closes vim/vim#5391) https://github.com/vim/vim/commit/64e74c9cc7d5aab215cf72d9bdd3aac32e128191 --- src/nvim/eval/typval.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 72ee45a03a..728e3a7fa3 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2732,16 +2732,7 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error) return n; } case VAR_SPECIAL: { - switch (tv->vval.v_special) { - case kSpecialVarTrue: { - return 1; - } - case kSpecialVarFalse: - case kSpecialVarNull: { - return 0; - } - } - break; + return tv->vval.v_special == kSpecialVarTrue ? 1 : 0; } case VAR_UNKNOWN: { emsgf(_(e_intern2), "tv_get_number(UNKNOWN)"); -- cgit From 1aacab49ea0e5cff94bd89595737b6af677f4490 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 5 Jan 2020 10:40:02 -0500 Subject: vim-patch:8.1.1579: dict and list could be GC'ed while displaying error Problem: Dict and list could be GC'ed while displaying error in a timer. (Yasuhiro Matsumoto) Solution: Block garbage collection when executing a timer. Add test_garbagecollect_soon(). Add "no_wait_return" to test_override(). (closes vim/vim#4571) https://github.com/vim/vim/commit/adc6714aac20f5462a0ecec50ab4806b2f3ab0db --- src/nvim/eval/typval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 728e3a7fa3..da97eccc65 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1306,7 +1306,7 @@ void tv_dict_item_remove(dict_T *const dict, dictitem_T *const item) dict_T *tv_dict_alloc(void) FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT { - dict_T *const d = xmalloc(sizeof(dict_T)); + dict_T *const d = xcalloc(1, sizeof(dict_T)); // Add the dict to the list of dicts for garbage collection. if (gc_first_dict != NULL) { -- cgit From d50c1123d5616c9757bb5707416696cda1a43716 Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Mon, 10 Feb 2020 18:34:18 +0100 Subject: fix: includes --- src/nvim/eval/typval.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index da97eccc65..16b38b47dc 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -15,6 +15,7 @@ #include "nvim/eval/encode.h" #include "nvim/eval/typval_encode.h" #include "nvim/eval.h" +#include "nvim/eval/user_funcs.h" #include "nvim/types.h" #include "nvim/assert.h" #include "nvim/memory.h" -- cgit From 5e815edece308a91296720cd6cb8d988af6c90c8 Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Tue, 11 Feb 2020 16:19:14 +0100 Subject: rename: user_funcs -> userfunc Lets stick with vim for now --- src/nvim/eval/typval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 16b38b47dc..c8b5fc294c 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -15,7 +15,7 @@ #include "nvim/eval/encode.h" #include "nvim/eval/typval_encode.h" #include "nvim/eval.h" -#include "nvim/eval/user_funcs.h" +#include "nvim/eval/userfunc.h" #include "nvim/types.h" #include "nvim/assert.h" #include "nvim/memory.h" -- cgit From 6da16ac931eec7be2487ee98e7f605fa12b0171d Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Tue, 3 Mar 2020 18:17:37 +0800 Subject: external pum: use floating point geometry; typval: add tv_dict_add_float --- src/nvim/eval/typval.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index c8b5fc294c..773e493d0b 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1634,6 +1634,28 @@ int tv_dict_add_nr(dict_T *const d, const char *const key, return OK; } +/// Add a floating point number entry to dictionary +/// +/// @param[out] d Dictionary to add entry to. +/// @param[in] key Key to add. +/// @param[in] key_len Key length. +/// @param[in] nr Floating point number to add. +/// +/// @return OK in case of success, FAIL when key already exists. +int tv_dict_add_float(dict_T *const d, const char *const key, + const size_t key_len, const float_T nr) +{ + dictitem_T *const item = tv_dict_item_alloc_len(key, key_len); + + item->di_tv.v_type = VAR_FLOAT; + item->di_tv.vval.v_float = nr; + if (tv_dict_add(d, item) == FAIL) { + tv_dict_item_free(item); + return FAIL; + } + return OK; +} + /// Add a special entry to dictionary /// /// @param[out] d Dictionary to add entry to. -- cgit From c477b19bdca0cc57e08f5fb93f647767ea84dd3e Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Wed, 29 Apr 2020 00:27:14 +0900 Subject: vim-patch:8.2.0084: complete item "user_data" can only be a string Problem: Complete item "user_data" can only be a string. Solution: Accept any type of variable. (closes vim/vim#5412) https://github.com/vim/vim/commit/0892832bb6c7e322fcae8560eaad5a8140ee4a06 --- src/nvim/eval/typval.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 773e493d0b..35130f6f40 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1429,6 +1429,23 @@ dictitem_T *tv_dict_find(const dict_T *const d, const char *const key, return TV_DICT_HI2DI(hi); } +/// Get a typval item from a dictionary and copy it into "rettv". +/// +/// @param[in] d Dictionary to check. +/// @param[in] key Dictionary key. +/// @param[in] rettv Return value. +/// @return OK in case of success or FAIL if nothing was found. +int tv_dict_get_tv(dict_T *d, const char *const key, typval_T *rettv) +{ + dictitem_T *const di = tv_dict_find(d, key, -1); + if (di == NULL) { + return FAIL; + } + + tv_copy(&di->di_tv, rettv); + return OK; +} + /// Get a number item from a dictionary /// /// Returns 0 if the entry does not exist. @@ -1588,6 +1605,26 @@ int tv_dict_add_list(dict_T *const d, const char *const key, return OK; } +/// Add a typval entry to dictionary. +/// +/// @param[out] d Dictionary to add entry to. +/// @param[in] key Key to add. +/// @param[in] key_len Key length. +/// +/// @return FAIL if out of memory or key already exists. +int tv_dict_add_tv(dict_T *d, const char *key, const size_t key_len, + typval_T *tv) +{ + dictitem_T *const item = tv_dict_item_alloc_len(key, key_len); + + tv_copy(tv, &item->di_tv); + if (tv_dict_add(d, item) == FAIL) { + tv_dict_item_free(item); + return FAIL; + } + return OK; +} + /// Add a dictionary entry to dictionary /// /// @param[out] d Dictionary to add entry to. -- cgit From 1805fb469a39d998f9bef0415999aa835d051044 Mon Sep 17 00:00:00 2001 From: Billy Su Date: Tue, 28 Apr 2020 23:21:50 +0800 Subject: vim-patch:8.2.0111: VAR_SPECIAL is also used for booleans Problem: VAR_SPECIAL is also used for booleans. Solution: Add VAR_BOOL for better type checking. https://github.com/vim/vim/commit/9b4a15d5dba354d2e1e02871470bad103f34769a --- src/nvim/eval/typval.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 35130f6f40..0daaf6c878 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1693,21 +1693,21 @@ int tv_dict_add_float(dict_T *const d, const char *const key, return OK; } -/// Add a special entry to dictionary +/// Add a boolean entry to dictionary /// /// @param[out] d Dictionary to add entry to. /// @param[in] key Key to add. /// @param[in] key_len Key length. -/// @param[in] val SpecialVarValue to add. +/// @param[in] val BoolVarValue to add. /// /// @return OK in case of success, FAIL when key already exists. -int tv_dict_add_special(dict_T *const d, const char *const key, - const size_t key_len, SpecialVarValue val) +int tv_dict_add_bool(dict_T *const d, const char *const key, + const size_t key_len, BoolVarValue val) { dictitem_T *const item = tv_dict_item_alloc_len(key, key_len); - item->di_tv.v_type = VAR_SPECIAL; - item->di_tv.vval.v_special = val; + item->di_tv.v_type = VAR_BOOL; + item->di_tv.vval.v_bool = val; if (tv_dict_add(d, item) == FAIL) { tv_dict_item_free(item); return FAIL; @@ -2013,12 +2013,15 @@ void tv_dict_alloc_ret(typval_T *const ret_tv) #define TYPVAL_ENCODE_CONV_NIL(tv) \ do { \ - tv->vval.v_special = kSpecialVarFalse; \ + tv->vval.v_special = kSpecialVarNull; \ tv->v_lock = VAR_UNLOCKED; \ } while (0) #define TYPVAL_ENCODE_CONV_BOOL(tv, num) \ - TYPVAL_ENCODE_CONV_NIL(tv) + do { \ + tv->vval.v_bool = kBoolVarFalse; \ + tv->v_lock = VAR_UNLOCKED; \ + } while (0) #define TYPVAL_ENCODE_CONV_NUMBER(tv, num) \ do { \ @@ -2293,6 +2296,7 @@ void tv_free(typval_T *tv) tv_dict_unref(tv->vval.v_dict); break; } + case VAR_BOOL: case VAR_SPECIAL: case VAR_NUMBER: case VAR_FLOAT: @@ -2324,6 +2328,7 @@ void tv_copy(const typval_T *const from, typval_T *const to) switch (from->v_type) { case VAR_NUMBER: case VAR_FLOAT: + case VAR_BOOL: case VAR_SPECIAL: { break; } @@ -2425,6 +2430,7 @@ void tv_item_lock(typval_T *const tv, const int deep, const bool lock) case VAR_STRING: case VAR_FUNC: case VAR_PARTIAL: + case VAR_BOOL: case VAR_SPECIAL: { break; } @@ -2588,6 +2594,9 @@ bool tv_equal(typval_T *const tv1, typval_T *const tv2, const bool ic, const char *s2 = tv_get_string_buf(tv2, buf2); return mb_strcmp_ic((bool)ic, s1, s2) == 0; } + case VAR_BOOL: { + return tv1->vval.v_bool == tv2->vval.v_bool; + } case VAR_SPECIAL: { return tv1->vval.v_special == tv2->vval.v_special; } @@ -2638,6 +2647,10 @@ bool tv_check_str_or_nr(const typval_T *const tv) EMSG(_("E728: Expected a Number or a String, Dictionary found")); return false; } + case VAR_BOOL: { + EMSG(_("E5299: Expected a Number or a String, Boolean found")); + return false; + } case VAR_SPECIAL: { EMSG(_("E5300: Expected a Number or a String")); return false; @@ -2677,6 +2690,7 @@ bool tv_check_num(const typval_T *const tv) { switch (tv->v_type) { case VAR_NUMBER: + case VAR_BOOL: case VAR_SPECIAL: case VAR_STRING: { return true; @@ -2721,6 +2735,7 @@ bool tv_check_str(const typval_T *const tv) { switch (tv->v_type) { case VAR_NUMBER: + case VAR_BOOL: case VAR_SPECIAL: case VAR_STRING: { return true; @@ -2791,8 +2806,11 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error) } return n; } + case VAR_BOOL: { + return tv->vval.v_bool == kBoolVarTrue ? 1 : 0; + } case VAR_SPECIAL: { - return tv->vval.v_special == kSpecialVarTrue ? 1 : 0; + return 0; } case VAR_UNKNOWN: { emsgf(_(e_intern2), "tv_get_number(UNKNOWN)"); @@ -2860,6 +2878,10 @@ float_T tv_get_float(const typval_T *const tv) EMSG(_("E894: Using a Dictionary as a Float")); break; } + case VAR_BOOL: { + EMSG(_("E362: Using a boolean value as a Float")); + break; + } case VAR_SPECIAL: { EMSG(_("E907: Using a special value as a Float")); break; @@ -2897,6 +2919,10 @@ const char *tv_get_string_buf_chk(const typval_T *const tv, char *const buf) } return ""; } + case VAR_BOOL: { + STRCPY(buf, encode_bool_var_names[tv->vval.v_bool]); + return buf; + } case VAR_SPECIAL: { STRCPY(buf, encode_special_var_names[tv->vval.v_special]); return buf; -- cgit From 6360cf7ce87407bd8a519b9a17f45b2148291904 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Tue, 30 Jun 2020 02:05:06 -0400 Subject: lua: Add ability to pass tables with __call vim-patch:8.2.1054: not so easy to pass a lua function to Vim vim-patch:8.2.1084: Lua: registering function has useless code I think I have also opened up the possibility for people to use these callbacks elsewhere, since I've added a new struct that we should be able to use. Also, this should allow us to determine what the state of a list is in Lua or a dictionary in Lua, since we now can track the luaref as we go. --- src/nvim/eval/typval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 0daaf6c878..89ca2db59b 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -16,6 +16,7 @@ #include "nvim/eval/typval_encode.h" #include "nvim/eval.h" #include "nvim/eval/userfunc.h" +#include "nvim/lua/executor.h" #include "nvim/types.h" #include "nvim/assert.h" #include "nvim/memory.h" @@ -301,6 +302,7 @@ void tv_list_free_list(list_T *const l) } list_log(l, NULL, NULL, "freelist"); + nlua_free_typval_list(l); xfree(l); } @@ -1374,6 +1376,7 @@ void tv_dict_free_dict(dict_T *const d) d->dv_used_next->dv_used_prev = d->dv_used_prev; } + nlua_free_typval_dict(d); xfree(d); } -- cgit From 6420615e3f703870ed898083f84d6e3515a8c279 Mon Sep 17 00:00:00 2001 From: Cédric Barreteau <> Date: Tue, 30 Jun 2020 18:39:54 +0200 Subject: vim-patch:8.2.0935: flattening a list with existing code is slow Problem: Flattening a list with existing code is slow. Solution: Add flatten(). (Mopp, closes vim/vim#3676) https://github.com/vim/vim/commit/077a1e670ad69ef4cefc22103ca6635bd269e764 --- src/nvim/eval/typval.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 89ca2db59b..576948f052 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -640,6 +640,53 @@ tv_list_copy_error: return NULL; } +/// Flatten "list" in place to depth "maxdepth". +/// Does nothing if "maxdepth" is 0. +/// +/// @param[in] list List to flatten +/// @param[in] maxdepth Maximum depth that will be flattened +/// +/// @return OK or FAIL +int tv_list_flatten(list_T *list, long maxdepth) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + listitem_T *item; + int n; + if (maxdepth == 0) { + return OK; + } + + n = 0; + item = list->lv_first; + while (item != NULL) { + fast_breakcheck(); + if (got_int) { + return FAIL; + } + if (item->li_tv.v_type == VAR_LIST) { + listitem_T *next = item->li_next; + + tv_list_drop_items(list, item, item); + tv_list_extend(list, item->li_tv.vval.v_list, next); + + if (item->li_prev == NULL) { + item = list->lv_first; + } else { + item = item->li_prev->li_next; + } + + if (++n >= maxdepth) { + n = 0; + item = next; + } + } else { + n = 0; + item = item->li_next; + } + } + return OK; +} + /// Extend first list with the second /// /// @param[out] l1 List to extend. -- cgit From fd57d69970e7947da0d69d744c13121668f91bd8 Mon Sep 17 00:00:00 2001 From: Cédric Barreteau <> Date: Tue, 30 Jun 2020 18:45:58 +0200 Subject: vim-patch:8.2.0937: asan failure in the flatten() test Problem: Asan failure in the flatten() test. Solution: Free the flattened list. https://github.com/vim/vim/commit/dcf59c37d0e1517439c4c0c4a6a5ca09c90157ad --- src/nvim/eval/typval.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 576948f052..d5db15afcc 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -651,6 +651,7 @@ int tv_list_flatten(list_T *list, long maxdepth) FUNC_ATTR_WARN_UNUSED_RESULT { listitem_T *item; + listitem_T *to_free; int n; if (maxdepth == 0) { return OK; @@ -668,12 +669,15 @@ int tv_list_flatten(list_T *list, long maxdepth) tv_list_drop_items(list, item, item); tv_list_extend(list, item->li_tv.vval.v_list, next); + tv_clear(&item->li_tv); + to_free = item; if (item->li_prev == NULL) { item = list->lv_first; } else { item = item->li_prev->li_next; } + xfree(to_free); if (++n >= maxdepth) { n = 0; -- cgit From 9f7f42ea0a4ba85aa27f9d8dc3833e854ce54703 Mon Sep 17 00:00:00 2001 From: Cédric Barreteau <> Date: Tue, 7 Jul 2020 21:02:22 +0200 Subject: Prevent `flatten` from taking a null list --- src/nvim/eval/typval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index d5db15afcc..e47403c656 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -648,7 +648,7 @@ tv_list_copy_error: /// /// @return OK or FAIL int tv_list_flatten(list_T *list, long maxdepth) - FUNC_ATTR_WARN_UNUSED_RESULT + FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT { listitem_T *item; listitem_T *to_free; -- cgit From e16f2cbd123b5a7bd75b5810ec7641a93c99c009 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 12 Jul 2020 19:04:35 -0400 Subject: vim-patch:8.2.0539: comparing two NULL list fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Comparing two NULL list fails. Solution: Change the order of comparing two lists. https://github.com/vim/vim/commit/7b293c730b07d1586688e622b8d9cbbb4a52379b N/A patches for version.c: vim-patch:8.2.1187: terminal2 test sometimes hangs in the GUI on Travis Problem: Terminal2 test sometimes hangs in the GUI on Travis. Solution: Disable Test_zz2_terminal_guioptions_bang() for now. https://github.com/vim/vim/commit/c85156bb897085d7f5a8e4e180287f87bf19b948 vim-patch:8.2.1188: memory leak with invalid json input Problem: Memory leak with invalid json input. Solution: Free all keys at the end. (Dominique Pellé, closes vim/vim#6443, closes vim/vim#6442) https://github.com/vim/vim/commit/6d3a7213f58da834b0fc869d05f87e86010c66cf vim-patch:8.2.1196: build failure with normal features Problem: Build failure with normal features. Solution: Add #ifdef. https://github.com/vim/vim/commit/83e7450053399942e1c9efa802c568b51d948541 vim-patch:8.2.1198: terminal2 test sometimes hangs in the GUI on Travis Problem: Terminal2 test sometimes hangs in the GUI on Travis. Solution: Move test function to terminal3 to see if the problem moves too. https://github.com/vim/vim/commit/a4b442614c5ca4ebf32acf5cf0b7b718496f1c94 --- src/nvim/eval/typval.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 89ca2db59b..2394eb8099 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -799,10 +799,14 @@ bool tv_list_equal(list_T *const l1, list_T *const l2, const bool ic, if (l1 == l2) { return true; } - if (l1 == NULL || l2 == NULL) { + if (tv_list_len(l1) != tv_list_len(l2)) { return false; } - if (tv_list_len(l1) != tv_list_len(l2)) { + if (tv_list_len(l1) == 0) { + // empty and NULL list are considered equal + return true; + } + if (l1 == NULL || l2 == NULL) { return false; } -- cgit From 9464399c8c8af44eea9c723f090e782af0346a1a Mon Sep 17 00:00:00 2001 From: Cédric Barreteau <> Date: Mon, 20 Jul 2020 20:21:49 +0200 Subject: Fix documentation The list parameter is an an [in,out] rather than just an [in]. --- src/nvim/eval/typval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index e47403c656..dcfd456ce3 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -643,7 +643,7 @@ tv_list_copy_error: /// Flatten "list" in place to depth "maxdepth". /// Does nothing if "maxdepth" is 0. /// -/// @param[in] list List to flatten +/// @param[in,out] list List to flatten /// @param[in] maxdepth Maximum depth that will be flattened /// /// @return OK or FAIL -- cgit From e0afec8a626d72d074f80bdbbc2cc753802ecaa4 Mon Sep 17 00:00:00 2001 From: erw7 Date: Thu, 23 Jul 2020 12:58:22 +0900 Subject: typval: fix incompatibility with vim The dict_add_string of vim accepts NULL as the value to add. But tv_dict_add_str didn't accept it. Change it to accept NULL as well as vim. --- src/nvim/eval/typval.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/eval/typval.c') diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index ef8e66a992..8dde78de3d 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1779,9 +1779,9 @@ int tv_dict_add_bool(dict_T *const d, const char *const key, int tv_dict_add_str(dict_T *const d, const char *const key, const size_t key_len, const char *const val) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ARG(1, 2) { - return tv_dict_add_allocated_str(d, key, key_len, xstrdup(val)); + return tv_dict_add_str_len(d, key, key_len, val, -1); } /// Add a string entry to dictionary @@ -1795,10 +1795,10 @@ int tv_dict_add_str(dict_T *const d, /// @return OK in case of success, FAIL when key already exists. int tv_dict_add_str_len(dict_T *const d, const char *const key, const size_t key_len, - char *const val, int len) + const char *const val, int len) FUNC_ATTR_NONNULL_ARG(1, 2) { - char *s = val ? val : ""; + char *s = NULL; if (val != NULL) { s = (len < 0) ? xstrdup(val) : xstrndup(val, (size_t)len); } @@ -1821,7 +1821,7 @@ int tv_dict_add_str_len(dict_T *const d, int tv_dict_add_allocated_str(dict_T *const d, const char *const key, const size_t key_len, char *const val) - FUNC_ATTR_NONNULL_ALL + FUNC_ATTR_NONNULL_ARG(1, 2) { dictitem_T *const item = tv_dict_item_alloc_len(key, key_len); -- cgit