aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-03-05 02:15:17 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:08:45 +0300
commit38dd81c136c2edbda66614622a4747bf1785af94 (patch)
treee1b16bc84bb67a2a1d0a81857e91df83a7260705
parentfaddd83db8a71623e78a4d919b2bb55e6a58439d (diff)
downloadrneovim-38dd81c136c2edbda66614622a4747bf1785af94.tar.gz
rneovim-38dd81c136c2edbda66614622a4747bf1785af94.tar.bz2
rneovim-38dd81c136c2edbda66614622a4747bf1785af94.zip
eval/typval: Fix SEGV in test_alot.vim test
-rw-r--r--src/nvim/eval/typval.c5
-rw-r--r--test/functional/eval/null_spec.lua6
-rw-r--r--test/unit/eval/typval_spec.lua7
3 files changed, 17 insertions, 1 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 326334f149..8d1ecf8f14 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1167,8 +1167,11 @@ void tv_dict_unref(dict_T *const d)
/// @return found item or NULL if nothing was found.
dictitem_T *tv_dict_find(const dict_T *const d, const char *const key,
const ptrdiff_t len)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
+ FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
+ if (d == NULL) {
+ return NULL;
+ }
hashitem_T *const hi = (len < 0
? hash_find(&d->dv_hashtab, (const char_u *)key)
: hash_find_len(&d->dv_hashtab, key, (size_t)len));
diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua
index f72d05f2a3..3b361ceeda 100644
--- a/test/functional/eval/null_spec.lua
+++ b/test/functional/eval/null_spec.lua
@@ -130,4 +130,10 @@ describe('NULL', function()
null_list_expr_test('is not not equal to itself', 'L != L', 0, 0)
null_list_expr_test('counts correctly', 'count([L], L)', 0, 1)
end)
+ describe('dict', function()
+ it('does not crash when indexing NULL dict', function()
+ eq('\nE716: Key not present in Dictionary: test\nE15: Invalid expression: v:_null_dict.test',
+ redir_exec('echo v:_null_dict.test'))
+ end)
+ end)
end)
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index ebd53469e8..937869a7bc 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -1568,5 +1568,12 @@ describe('typval.c', function()
end)
end)
end)
+ describe('indexing', function()
+ describe('find', function()
+ itp('works with NULL dict', function()
+ eq(nil, lib.tv_dict_find(nil, '', 0))
+ end)
+ end)
+ end)
end)
end)