mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-01-12 19:20:38 +00:00
Lunatic: fix map-text loading.
The file descriptor was closed from Lua code, causing the subsequent kfilelength() to fail and attempt an allocation of (size_t)-1 bytes. git-svn-id: https://svn.eduke32.com/eduke32@5809 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
f0cb3ea994
commit
edd7a82be8
2 changed files with 4 additions and 6 deletions
|
@ -1705,7 +1705,9 @@ local function readintostr_mod(fn)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return defs_c.readintostr(fd)
|
local ret = defs_c.readintostr(fd)
|
||||||
|
ffiC.kclose(fd)
|
||||||
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -399,26 +399,22 @@ int32_t sectorofwall_noquick(int16_t theline);
|
||||||
]]
|
]]
|
||||||
|
|
||||||
-- Reads the whole file given by the k* file descriptor into a Lua string.
|
-- Reads the whole file given by the k* file descriptor into a Lua string.
|
||||||
-- Always closes the file descriptor.
|
-- Does not close the file descriptor.
|
||||||
function readintostr(fd, kopen4load_func)
|
function readintostr(fd, kopen4load_func)
|
||||||
-- XXX: this is pretty much the same as the code in L_RunOnce()
|
-- XXX: this is pretty much the same as the code in L_RunOnce()
|
||||||
|
|
||||||
local sz = ffiC.kfilelength(fd)
|
local sz = ffiC.kfilelength(fd)
|
||||||
if (sz == 0) then
|
if (sz == 0) then
|
||||||
ffiC.kclose(fd)
|
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
if (sz < 0) then
|
if (sz < 0) then
|
||||||
ffi.kclose(fd)
|
|
||||||
error("INTERNAL ERROR: kfilelength() returned negative length")
|
error("INTERNAL ERROR: kfilelength() returned negative length")
|
||||||
end
|
end
|
||||||
|
|
||||||
local str = ffi.new("char [?]", sz)
|
local str = ffi.new("char [?]", sz)
|
||||||
local readlen = ffiC.kread(fd, str, sz)
|
local readlen = ffiC.kread(fd, str, sz)
|
||||||
|
|
||||||
ffiC.kclose(fd); fd=-1
|
|
||||||
|
|
||||||
if (readlen ~= sz) then
|
if (readlen ~= sz) then
|
||||||
error("INTERNAL ERROR: couldn't read file wholly")
|
error("INTERNAL ERROR: couldn't read file wholly")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue