fix SIGSEGV when reading from a non-existant file (#4453)

When a tool (tested with spirv-dis and spirv-as) runs on a file that
does not exist, it notifies the user and tries to close the stream that
was never successfully opened.
This commit is contained in:
5265644D61736F6E 2021-08-16 09:44:22 -04:00 committed by GitHub
parent 00b106e769
commit 881001070a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,7 +89,7 @@ bool ReadBinaryFile(const char* filename, std::vector<T>* data) {
ReadFile(fp, data);
bool succeeded = WasFileCorrectlyRead<T>(fp, filename);
if (use_file) fclose(fp);
if (use_file && fp) fclose(fp);
return succeeded;
}
@ -111,7 +111,7 @@ bool ReadTextFile(const char* filename, std::vector<T>* data) {
ReadFile(fp, data);
bool succeeded = WasFileCorrectlyRead<T>(fp, filename);
if (use_file) fclose(fp);
if (use_file && fp) fclose(fp);
return succeeded;
}