From b5bf12e8cfe42834fd782918be4de8bcae61ce04 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 22 Jan 2017 09:12:43 +0300 Subject: utils: bugfix --- utils/helpers/file.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/helpers/file.hpp b/utils/helpers/file.hpp index febe98f..e767bbc 100644 --- a/utils/helpers/file.hpp +++ b/utils/helpers/file.hpp @@ -10,18 +10,24 @@ #include #include #include +#include #include namespace file { + inline std::size_t cast_to_size_t(std::streamoff size) + { + assert(size >= 0); + assert(static_cast::type>(size) <= std::numeric_limits::max()); + return static_cast(size); + } + inline std::size_t get_file_size(const std::string& path) { std::ifstream ifs; ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); ifs.open(path, std::ifstream::binary | std::ifstream::ate); - const auto size = static_cast(ifs.tellg()); - assert(size <= static_cast(std::numeric_limits::max())); - return static_cast(size); + return cast_to_size_t(ifs.tellg()); } inline std::vector read_file(const std::string& path) -- cgit v1.2.3