From f6af7c442df3e569492ced730e70d1bc72356c5e Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 15 May 2021 21:22:50 +0300 Subject: get rid of SafeInt --- src/module.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/module.cpp') diff --git a/src/module.cpp b/src/module.cpp index 3f4764c..f05ef03 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -5,10 +5,10 @@ #include -#include #include #include +#include #include #include #include @@ -38,8 +38,11 @@ Address Module::translate_offline_address(Address offline) const { throw std::range_error{invalid_offline_address(offline)}; const auto offset = offline - get_offline_base(); auto online = offset; - if (!SafeAdd(online, get_online_base(), online)) + // Check that it fits the address space. + const auto max_addr = std::numeric_limits::max(); + if (online > max_addr - get_online_base()) throw std::range_error{invalid_offline_address(offline)}; + online += get_online_base(); return online; } @@ -48,8 +51,11 @@ Address Module::translate_online_address(Address online) const { throw std::range_error{invalid_online_address(online)}; const auto offset = online - get_online_base(); auto offline = offset; - if (!SafeAdd(offline, get_offline_base(), offline)) + // Check that it fits the address space. + const auto max_addr = std::numeric_limits::max(); + if (offline > max_addr - get_offline_base()) throw std::range_error{invalid_online_address(offline)}; + offline += get_offline_base(); return offline; } -- cgit v1.3