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 7699af1e13
commit bb7bcff086
+2 -2
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;
}