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:
bart@bart
2009-08-26 17:20:23 +02:00
parent a3bff7cde9
commit 0aae22d523
2 changed files with 12 additions and 2 deletions
@@ -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;
} }
@@ -274,4 +282,4 @@ namespace physfs
} // physfs } // physfs
} // filesystem } // filesystem
} // love } // love