From c87039b6c47f3e73b644569efe19c7fe2c37df87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 3 Jun 2020 00:39:05 +0200 Subject: [PATCH] Fixes issue #89 ("priv_size_from_mapping_size() calculates wrong value") --- include/boost/interprocess/mapped_region.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/interprocess/mapped_region.hpp b/include/boost/interprocess/mapped_region.hpp index 1fb6408..2101628 100644 --- a/include/boost/interprocess/mapped_region.hpp +++ b/include/boost/interprocess/mapped_region.hpp @@ -297,7 +297,7 @@ inline bool mapped_region::priv_flush_param_check if(m_base == 0) return false; - if(mapping_offset >= m_size || (mapping_offset + numbytes) > m_size){ + if(mapping_offset >= m_size || numbytes > (m_size - size_t(mapping_offset))){ return false; } @@ -346,14 +346,14 @@ inline void mapped_region::priv_size_from_mapping_size (offset_t mapping_size, offset_t offset, offset_t page_offset, std::size_t &size) { //Check if mapping size fits in the user address space - //as offset_t is the maximum file size and its signed. + //as offset_t is the maximum file size and it's signed. if(mapping_size < offset || boost::uintmax_t(mapping_size - (offset - page_offset)) > boost::uintmax_t(std::size_t(-1))){ error_info err(size_error); throw interprocess_exception(err); } - size = static_cast(mapping_size - (offset - page_offset)); + size = static_cast(mapping_size - offset); } inline offset_t mapped_region::priv_page_offset_addr_fixup(offset_t offset, const void *&address)