From c7c7163a82457d71ecb80e5e3d831dd808117483 Mon Sep 17 00:00:00 2001 From: mandreyel Date: Tue, 27 Nov 2018 12:02:46 +0100 Subject: [PATCH] Fix file length calculation bug and half-missing comment --- include/mio/detail/mmap.ipp | 2 +- include/mio/mmap.hpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/mio/detail/mmap.ipp b/include/mio/detail/mmap.ipp index c5be288..d38a1b8 100644 --- a/include/mio/detail/mmap.ipp +++ b/include/mio/detail/mmap.ipp @@ -331,7 +331,7 @@ void basic_mmap::map(const handle_type handle, } const auto ctx = detail::memory_map(handle, offset, - length == map_entire_file ? file_size : length, + length == map_entire_file ? (file_size - offset) : length, AccessMode, error); if(!error) { diff --git a/include/mio/mmap.hpp b/include/mio/mmap.hpp index cb686ca..9de9d93 100644 --- a/include/mio/mmap.hpp +++ b/include/mio/mmap.hpp @@ -57,7 +57,7 @@ template struct basic_mmap { using value_type = ByteT; - using size_type = int64_t; + using size_type = size_t; using reference = value_type&; using const_reference = const value_type&; using pointer = value_type*; @@ -90,9 +90,11 @@ private: handle_type file_mapping_handle_ = INVALID_HANDLE_VALUE; #endif - // some complexity in that we must not close the file handle if user provided it, - // but we must close it if we obtained it using the provided path. For this reason, - // this flag is used to determine when to close file_handle_. + // Letting user map a file using both an existing file handle and a path + // introcudes some complexity in that we must not close the file handle if + // user provided it, but we must close it if we obtained it using the + // provided path. For this reason, this flag is used to determine when to + // close file_handle_. bool is_handle_internal_; public: