test(unit/eval/typval_spec): don't dereference NULL last_msg_hist

If last_msg_hist is NULL, check_emsg will cause the running test process
to SIGSEGV from trying to access the msg member.
This commit is contained in:
Sean Dewar 2021-09-24 22:42:31 +01:00 committed by zeertzjq
parent 7f8c1e53a6
commit 1ffd20a26e

View File

@ -101,12 +101,13 @@ local function check_emsg(f, msg)
saved_last_msg_hist = nil
end
local ret = {f()}
local last_msg = lib.last_msg_hist ~= nil and ffi.string(lib.last_msg_hist.msg) or nil
if msg ~= nil then
eq(msg, ffi.string(lib.last_msg_hist.msg))
eq(msg, last_msg)
neq(saved_last_msg_hist, lib.last_msg_hist)
else
if saved_last_msg_hist ~= lib.last_msg_hist then
eq(nil, ffi.string(lib.last_msg_hist.msg))
eq(nil, last_msg)
else
eq(saved_last_msg_hist, lib.last_msg_hist)
end