Skip to content

Commit 4301953

Browse files
kaezaest31
authored andcommittedFeb 8, 2016
builtin: Fix print crashing on nil "holes".
The engine implementation of `print` packs the varargs into a table and passes the table directly to `table.concat`. If you pass any value not supported by `table.concat` (particularly `nil`), the server crashes. This is unexpected behavior, as `print` is supposed to be able to work with anything. This patch changes the implementation so it first converts all arguments using `tostring`, which fixes the issue and makes the custom `print` function compatible with the stock Lua behavior.
1 parent 16c7008 commit 4301953

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎builtin/init.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ if core.print then
1212
-- Override native print and use
1313
-- terminal if that's turned on
1414
function print(...)
15-
core_print(table.concat({...}, "\t"))
15+
local n, t = select("#", ...), { ... }
16+
for i = 1, n do
17+
t[i] = tostring(t[i])
18+
end
19+
core_print(table.concat(t, "\t"))
1620
end
1721
core.print = nil -- don't pollute our namespace
1822
end

0 commit comments

Comments
 (0)
Please sign in to comment.