mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 05:51:20 +00:00
Fix crash when trying to open unreadable IWAD files
This commit is contained in:
parent
0a30c19138
commit
349a2e9235
3 changed files with 20 additions and 2 deletions
|
@ -165,6 +165,23 @@ bool FileExists (const char *filename)
|
|||
return res && !isdir;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FileReadable
|
||||
//
|
||||
// Returns true if the file can be read.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
bool FileReadable(const char *filename)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
return access (filename, R_OK) == 0;
|
||||
#else
|
||||
return _access (filename, 4) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DirExists
|
||||
|
|
|
@ -33,6 +33,7 @@ char(&_ArraySizeHelper(T(&array)[N]))[N];
|
|||
#define myoffsetof(type,identifier) ((size_t)&((type *)alignof(type))->identifier - alignof(type))
|
||||
|
||||
bool FileExists (const char *filename);
|
||||
bool FileReadable (const char *filename);
|
||||
bool DirExists(const char *filename);
|
||||
bool DirEntryExists (const char *pathname, bool *isdir = nullptr);
|
||||
bool GetFileInfo(const char* pathname, size_t* size, time_t* time);
|
||||
|
|
|
@ -577,10 +577,10 @@ int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad,
|
|||
// -iwad not found or not specified. Revert back to standard behavior.
|
||||
if (mFoundWads.Size() == numFoundWads) iwadparm = nullptr;
|
||||
|
||||
// Check for symbolic links leading to non-existent files.
|
||||
// Check for symbolic links leading to non-existent files and for files that are unreadable.
|
||||
for (unsigned int i = 0; i < mFoundWads.Size(); i++)
|
||||
{
|
||||
if (!FileExists(mFoundWads[i].mFullPath)) mFoundWads.Delete(i);
|
||||
if (!FileExists(mFoundWads[i].mFullPath) || !FileReadable(mFoundWads[i].mFullPath)) mFoundWads.Delete(i);
|
||||
}
|
||||
|
||||
// Now check if what got collected actually is an IWAD.
|
||||
|
|
Loading…
Reference in a new issue