Check PHYSFS_init return value

PHYSFS_init is not guaranteed to succeed.  Using PHYSFS functions after
PHYSFS_init fails is likely to fail badly.  On Windows, failure may take
the form of a crash in ntdll.  Avoid this by exiting gracefully.
This commit is contained in:
Kp 2018-12-08 23:36:18 +00:00
parent d83972dfbb
commit a705104e84
2 changed files with 4 additions and 2 deletions

View file

@ -1294,7 +1294,8 @@ static void terminate_handler()
main = '''
PHYSFS_File *f;
char b[1] = {0};
PHYSFS_init("");
if (!PHYSFS_init(""))
return 1;
f = PHYSFS_openWrite("a");
PHYSFS_sint64 w = PHYSFS_write(f, b, 1, 1);
(void)w;

View file

@ -104,7 +104,8 @@ bool PHYSFSX_init(int argc, char *argv[])
#define base_dir PHYSFS_getBaseDir()
#endif
PHYSFS_init(argv[0]);
if (!PHYSFS_init(argv[0]))
Error("Failed to init PhysFS: %s", PHYSFS_getLastError());
PHYSFS_permitSymbolicLinks(1);
#ifdef macintosh