Skip to content

Commit

Permalink
Deal with table.pack corner-cases properly (#1603)
Browse files Browse the repository at this point in the history
Turns out we can't rely on the len operator in all cases,
as it may get confused depending on where the `nil`s are,
so always use the `n` field instead, as that *is* reliable.

Re: #1535
  • Loading branch information
NiLuJe committed Apr 23, 2023
1 parent ac93e1a commit 0bb499c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ffi/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function util.execute(...)
local pid = C.fork()
if pid == 0 then
local args = table.pack(...)
os.exit(C.execl(args[1], unpack(args, 1, #args+1))) -- Last arg must be a NULL pointer
os.exit(C.execl(args[1], unpack(args, 1, args.n+1))) -- Last arg must be a NULL pointer
end
local status = ffi.new('int[1]')
C.waitpid(pid, status, 0)
Expand Down Expand Up @@ -756,7 +756,7 @@ This function was inspired by Qt:
function util.template(str, ...)
local params = table.pack(...)
-- shortcut:
if #params == 0 then return str end
if params.n == 0 then return str end
local result = string.gsub(str, "%%([1-9][0-9]?)",
function(i)
return params[tonumber(i)]
Expand Down

0 comments on commit 0bb499c

Please sign in to comment.