fix(test): fix issues detected by running unittests in ASAN/UBSAN

This commit is contained in:
bfredl 2023-01-30 14:46:28 +01:00
parent d6d6ab3f8e
commit 42999a8d64
3 changed files with 5 additions and 5 deletions

View File

@ -821,6 +821,9 @@ void nlua_init(char **argv, int argc, int lua_arg0)
luaL_openlibs(lstate); luaL_openlibs(lstate);
if (!nlua_state_init(lstate)) { if (!nlua_state_init(lstate)) {
os_errmsg(_("E970: Failed to initialize builtin lua modules\n")); os_errmsg(_("E970: Failed to initialize builtin lua modules\n"));
#ifdef EXITFREE
nlua_common_free_all_mem(lstate);
#endif
os_exit(1); os_exit(1);
} }

View File

@ -1182,7 +1182,7 @@ static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_rig
assert(x->ptr[i] != x->ptr[j]); assert(x->ptr[i] != x->ptr[j]);
} }
} }
} else { } else if (x->n > 0) {
*last = x->key[x->n - 1].pos; *last = x->key[x->n - 1].pos;
} }
return n_keys; return n_keys;

View File

@ -1677,7 +1677,7 @@ describe('typval.c', function()
eq(nil, lib.tv_dict_find(nil, 'test', -1)) eq(nil, lib.tv_dict_find(nil, 'test', -1))
eq(nil, lib.tv_dict_find(nil, nil, 0)) eq(nil, lib.tv_dict_find(nil, nil, 0))
end) end)
itp('works with NULL key', function() itp('works with empty key', function()
local lua_d = { local lua_d = {
['']=0, ['']=0,
t=1, t=1,
@ -1692,7 +1692,6 @@ describe('typval.c', function()
alloc_log:check({}) alloc_log:check({})
local dis = dict_items(d) local dis = dict_items(d)
eq({0, '', dis['']}, {tv_dict_find(d, '', 0)}) eq({0, '', dis['']}, {tv_dict_find(d, '', 0)})
eq({0, '', dis['']}, {tv_dict_find(d, nil, 0)})
end) end)
itp('works with len properly', function() itp('works with len properly', function()
local lua_d = { local lua_d = {
@ -1910,8 +1909,6 @@ describe('typval.c', function()
} }
local d = dict(lua_d) local d = dict(lua_d)
eq(lua_d, dct2tbl(d)) eq(lua_d, dct2tbl(d))
eq({{type='fref', fref='tr'}, true},
{tv_dict_get_callback(d, nil, 0)})
eq({{type='fref', fref='tr'}, true}, eq({{type='fref', fref='tr'}, true},
{tv_dict_get_callback(d, '', -1)}) {tv_dict_get_callback(d, '', -1)})
eq({{type='none'}, true}, eq({{type='none'}, true},