mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +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)
|
||||
{
|
||||
if (!PHYSFS_exists(filename))
|
||||
throw Exception("File %s doesn't exist", filename);
|
||||
return new File(filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,15 @@ namespace physfs
|
||||
int w_newFile(lua_State * L)
|
||||
{
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
@@ -274,4 +282,4 @@ namespace physfs
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
} // love
|
||||
|
||||
Reference in New Issue
Block a user