diff options
author | 5265644D61736F6E <61918637+5265644D61736F6E@users.noreply.github.com> | 2021-08-16 16:44:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 16:44:22 +0300 |
commit | 881001070a8f3baf1ee5d7ef3cbc6e76e4015ce0 (patch) | |
tree | df7916eed6f5c38a9953110d717bf3ba16d042df /tools | |
parent | 00b106e769843ad4076b4d0fffb3ab89ec7a1a97 (diff) |
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.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/io.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/io.h b/tools/io.h index aff9eabd9..83a85c1d1 100644 --- a/tools/io.h +++ b/tools/io.h @@ -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; } |