aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-05-11 02:01:11 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-05-11 02:01:11 +0300
commit4dd79d590f88834d1911291c6c930bd732935408 (patch)
treeec3cd93750525e006c0ebd429c6577208cb69610 /utils
parentcode style & refactoring (diff)
downloadaes-tools-4dd79d590f88834d1911291c6c930bd732935408.tar.gz
aes-tools-4dd79d590f88834d1911291c6c930bd732935408.zip
utils: exceptions instead of asserts
Diffstat (limited to 'utils')
-rw-r--r--utils/helpers/file.hpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/utils/helpers/file.hpp b/utils/helpers/file.hpp
index e767bbc..48e4c51 100644
--- a/utils/helpers/file.hpp
+++ b/utils/helpers/file.hpp
@@ -3,12 +3,12 @@
// For details, see https://github.com/egor-tensin/aes-tools.
// Distributed under the MIT License.
-#include <cassert>
#include <cstddef>
#include <fstream>
#include <iterator>
#include <limits>
+#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>
@@ -17,8 +17,11 @@ namespace file
{
inline std::size_t cast_to_size_t(std::streamoff size)
{
- assert(size >= 0);
- assert(static_cast<std::make_unsigned<std::streamoff>::type>(size) <= std::numeric_limits<std::size_t>::max());
+ if (size < 0)
+ throw std::range_error{"file::cast_to_size_t: something went really wrong"};
+ typedef std::make_unsigned<std::streamoff>::type unsigned_streamoff;
+ if (static_cast<unsigned_streamoff>(size) > std::numeric_limits<std::size_t>::max())
+ throw std::range_error{"file::cast_to_size_t: this file is too large"};
return static_cast<std::size_t>(size);
}
@@ -41,8 +44,8 @@ namespace file
std::vector<char> src_buf;
src_buf.reserve(size);
src_buf.assign(
- std::istreambuf_iterator<char>(ifs),
- std::istreambuf_iterator<char>());
+ std::istreambuf_iterator<char>{ifs},
+ std::istreambuf_iterator<char>{});
return src_buf;
}