Skip to content
Permalink
Browse files

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.
  • Loading branch information
vLKp committed Dec 8, 2018
1 parent d83972d commit a705104e8412573f8bce26625bc4fffa42b2da9d
Showing with 4 additions and 2 deletions.
  1. +2 −1 SConstruct
  2. +2 −1 similar/misc/physfsx.cpp
@@ -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;
@@ -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

0 comments on commit a705104

Please sign in to comment.
You can’t perform that action at this time.