mirror of
https://github.com/love2d/love.git
synced 2026-08-20 12:40:20 +02:00
Fixed PHYSFS_fileLength segfault on non-existant files by checking if a file exists when a file object is created
This commit is contained in:
@@ -142,6 +142,8 @@ namespace physfs
|
|||||||
|
|
||||||
File * Filesystem::newFile(const char *filename)
|
File * Filesystem::newFile(const char *filename)
|
||||||
{
|
{
|
||||||
|
if (!PHYSFS_exists(filename))
|
||||||
|
throw Exception("File %s doesn't exist", filename);
|
||||||
return new File(filename);
|
return new File(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,15 @@ namespace physfs
|
|||||||
int w_newFile(lua_State * L)
|
int w_newFile(lua_State * L)
|
||||||
{
|
{
|
||||||
const char * filename = luaL_checkstring(L, 1);
|
const char * filename = luaL_checkstring(L, 1);
|
||||||
File * t = instance->newFile(filename);
|
File * t;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
t = instance->newFile(filename);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
return luaL_error(L, e.what());
|
||||||
|
}
|
||||||
luax_newtype(L, "File", FILESYSTEM_FILE_T, (void*)t);
|
luax_newtype(L, "File", FILESYSTEM_FILE_T, (void*)t);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user