diff options
-rw-r--r-- | src/util.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/util.cc b/src/util.cc index 9052118..3517e0b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -24,13 +24,17 @@ std::string readFile(const std::string& fileName) std::ifstream ifs(fileName.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - std::ifstream::pos_type fileSize = ifs.tellg(); + auto size = ifs.tellg(); + if(size < 0) + { + return {}; + } ifs.seekg(0, std::ios::beg); - std::vector<char> bytes(static_cast<std::size_t>(fileSize)); - ifs.read(bytes.data(), fileSize); + std::string bytes(static_cast<std::size_t>(size), '\0'); + ifs.read(bytes.data(), static_cast<std::streamsize>(bytes.size())); - return {bytes.data(), static_cast<std::size_t>(fileSize)}; + return bytes; } ctor::language languageFromExtension(const std::filesystem::path& file) |