diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-28 18:26:24 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-28 18:26:24 -0700 |
commit | fb0d9509f23472df14d03d93d333d242d23bd2bd (patch) | |
tree | 40afeae744cd0355e27f18e45f2911c1d01c31f3 /src/support/file.cpp | |
parent | 97972db66d30c1acb716e4f7a421f1fbe7410927 (diff) | |
parent | 5cc2c2182332cd17bf12e3cdb58e61d0582eafc1 (diff) | |
download | binaryen-fb0d9509f23472df14d03d93d333d242d23bd2bd.tar.gz binaryen-fb0d9509f23472df14d03d93d333d242d23bd2bd.tar.bz2 binaryen-fb0d9509f23472df14d03d93d333d242d23bd2bd.zip |
Merge pull request #287 from WebAssembly/vs2015_fixes
VS2015 fixes
Diffstat (limited to 'src/support/file.cpp')
-rw-r--r-- | src/support/file.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/support/file.cpp b/src/support/file.cpp index 8813750d4..c93086990 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -17,6 +17,7 @@ #include "support/file.h" #include <cstdlib> +#include <limits> template <typename T> T wasm::read_file(const std::string &filename, bool debug) { @@ -27,8 +28,13 @@ T wasm::read_file(const std::string &filename, bool debug) { exit(EXIT_FAILURE); } infile.seekg(0, std::ios::end); - size_t insize = infile.tellg(); - T input(insize + 1, '\0'); + std::streampos insize = infile.tellg(); + if (size_t(insize) >= std::numeric_limits<size_t>::max()) { + // Building a 32-bit executable where size_t == 32 bits, we are not able to create strings larger than 2^32 bytes in length, so must abort here. + std::cerr << "Failed opening '" << filename << "': Input file too large: " << insize << " bytes. Try rebuilding in 64-bit mode." << std::endl; + exit(EXIT_FAILURE); + } + T input(size_t(insize) + 1, '\0'); infile.seekg(0); infile.read(&input[0], insize); return input; |