eval/typval: Fix SEGV in test_alot.vim test

This commit is contained in:
ZyX 2017-03-05 02:15:17 +03:00
parent faddd83db8
commit 38dd81c136
3 changed files with 17 additions and 1 deletions

View File

@ -1167,8 +1167,11 @@ void tv_dict_unref(dict_T *const d)
/// @return found item or NULL if nothing was found. /// @return found item or NULL if nothing was found.
dictitem_T *tv_dict_find(const dict_T *const d, const char *const key, dictitem_T *tv_dict_find(const dict_T *const d, const char *const key,
const ptrdiff_t len) 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 hashitem_T *const hi = (len < 0
? hash_find(&d->dv_hashtab, (const char_u *)key) ? hash_find(&d->dv_hashtab, (const char_u *)key)
: hash_find_len(&d->dv_hashtab, key, (size_t)len)); : hash_find_len(&d->dv_hashtab, key, (size_t)len));

View File

@ -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('is not not equal to itself', 'L != L', 0, 0)
null_list_expr_test('counts correctly', 'count([L], L)', 0, 1) null_list_expr_test('counts correctly', 'count([L], L)', 0, 1)
end) 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) end)

View File

@ -1568,5 +1568,12 @@ describe('typval.c', function()
end) end)
end) 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)
end) end)