mirror of
https://github.com/neovim/neovim.git
synced 2026-09-12 17:11:02 +00:00
fix(strings): non fatal errors for [NULL] safety in vim_snprintf
context: vim_snprintf provides a "portable" replacement for a system vsnprintf(). However we rely on system vsnprintf() in places. This is quite arbitrary. I want to use system vsnprintf() only, and reduce the machinery in string.c for typval printf only, which will delet a lot of duplicated code. The biggest hurdle here is not "portably" (we only support sane c runtimes) but the following discrepancy: standard libc printf() considers NULL args to %s to be undefined behavior strictly while vim_snprintf() _defacto_ allows this by replacement to "[NULL]" IMO, this should be seen as "graceful" error handling (nicer than crashing on the user), not a valid means to have the string "[NULL]" intentionally be shoved in the users face. more robust code should explicitly check for NULL and replace it with a _appropriate_ fallback for the situation, depending on what a NULL string actually means in the context (unnamed buffer? anonymous namespace? global augroup?) soo, this PR provides the most _gently_ incremental nudge towards considering this case again as an error one could possible imagine. If sanitizers are complied in, this minor incursion gets printed into the sanitizers' log as a "report-and-continue" error with a traceback. This doesn't annoy the end user or "stop the world" in the test suite, but the CI will see the reported error and fail the build, just like other non-fatal CI errors.
This commit is contained in:
@@ -59,15 +59,15 @@ describe('print', function()
|
||||
eq('', exec_capture('luafile ' .. fname))
|
||||
-- TODO(bfredl): these look weird, print() should not use "E5114:" style errors..
|
||||
eq(
|
||||
'Vim(lua):E5108: Lua: E5114: Converting print argument #2: [NULL]',
|
||||
'Vim(lua):E5108: Lua: E5114: Converting print argument #2: nil',
|
||||
pcall_err(command, 'lua print("foo", v_nilerr, "bar")')
|
||||
)
|
||||
eq(
|
||||
'Vim(lua):E5108: Lua: E5114: Converting print argument #2: Xtest-functional-lua-overrides-luafile:2: abc',
|
||||
pcall_err(command, 'lua print("foo", v_abcerr, "bar")')
|
||||
)
|
||||
eq(
|
||||
'Vim(lua):E5108: Lua: E5114: Converting print argument #2: <Unknown error: lua_tolstring returned NULL for tostring result>',
|
||||
matches(
|
||||
'^Vim%(lua%):E5108: Lua: E5114: Converting print argument #2: table: 0x%x+$',
|
||||
pcall_err(command, 'lua print("foo", v_tblout, "bar")')
|
||||
)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user