lua/executor: Fix crash when printing empty string (#7157)

This commit is contained in:
Nikolai Aleksandrovich Pavlov 2017-08-13 18:37:35 +03:00 committed by ckelsel
parent e6c528d9fc
commit d0cb175cab
2 changed files with 8 additions and 1 deletions

View File

@ -519,7 +519,7 @@ static int nlua_print(lua_State *const lstate)
}
msg((char_u *)str + start);
}
if (str[len - 1] == NUL) { // Last was newline
if (len && str[len - 1] == NUL) { // Last was newline
msg((char_u *)"");
}
}

View File

@ -69,6 +69,13 @@ describe('print', function()
eq('\nT^@', redir_exec([[lua print("T\0")]]))
eq('\nT\n', redir_exec([[lua print("T\n")]]))
end)
it('prints empty strings correctly', function()
-- Regression: first test used to crash
eq('', redir_exec('lua print("")'))
eq('\n def', redir_exec('lua print("", "def")'))
eq('\nabc ', redir_exec('lua print("abc", "")'))
eq('\nabc def', redir_exec('lua print("abc", "", "def")'))
end)
end)
describe('debug.debug', function()